Multiple_Linear_Regression
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# In[2]:
myfile="D:\Sunny115\week2_50_Startups.csv"
dataset=pd.read_csv(myfile)
X=dataset.iloc[:,:-1].values
y=dataset.iloc[:,-1].values
# In[6]:
#encoding categorical data
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder
ct=ColumnTransformer(transformers=[('encoder',OneHotEncoder(),[3])],remainder='passthrough')
X=np.array(ct.fit_transform(X))
# In[8]:
print(X)
# In[13]:
#splitting the dataset
from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2,random_state=0)
# In[14]:
from sklearn.linear_model import LinearRegression
regressor=LinearRegression()
regressor.fit(X_train,y_train)
# In[15]:
y_pred=regressor.predict(X_test)
print(y_test)
print(y_pred)
# In[16]:
from sklearn.metrics import r2_score
r2_score(y_test,y_pred)
# In[ ]:
Comments
Post a Comment