I'm beginner working on python machine learning using google colab . i face issue i can't apply linear regression on excel file
price is output or Y
other fields on excel is input
so
How to clean data ?
after that How to apply linear regressin for this excel file
what i try
Python
import pandas as pd
df=pd.read_excel('Data_Train.xlsx')file attached with post
/forums/uploadfile/e2e758/01302024213902PM/Data_Train.zip
/forums/uploadfile/e2e758/01302024213902PM/Data_Train.xlsx

Amira BedhiafiRank #601 · 4K reputationPosted Jan 31, 2024, 6:16 AM EST
Try the following :
import pandas as pd from sklearn.model_selection import train_test_split from sklearn.linear_model import LinearRegression from sklearn.metrics import mean_squared_error df = pd.read_excel('Data_Train.xlsx') # For example, if there are missing values, you can fill them with the mean or median. # df.fillna(df.mean(), inplace=True) X = df.drop('price', axis=1) # Input features Y = df['price'] # Output variable # Here I split the data into training and testing sets X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, random_state=0) model = LinearRegression() model.fit(X_train, Y_train) predictions = model.predict(X_test) mse = mean_squared_error(Y_test, predictions) print(f"Mean Squared Error: {mse}")Rohit GuptaRank #11 · 59.9K reputationPosted Jan 30, 2024, 9:32 PM EST
Hi
Please refer to https://www.c-sharpcorner.com/article/linear-regression2/
Thanks
Tuhin PaulRank #7 · 71.9K reputationPosted Feb 2, 2024, 10:18 AM EST
To apply linear regression on an Excel file using Python in Google Colab, check below: