Simple Linear Regression
Simple Linear Regression
Simple Linear Regression
# In[4]:
myfile="D:\Sunny115\week2_Salary_Data.csv"
dataset=pd.read_csv(myfile)
X=dataset.iloc[:,:-1].values
y=dataset.iloc[:,-1].values
# In[5]:
from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=1/3,random_st
ate=0)
# In[6]:
from sklearn.linear_model import LinearRegression
regressor=LinearRegression()
regressor.fit(X_train,y_train)
# In[7]:
print(X_train)
# In[9]:
y_pred=regressor.predict(X_test)
print(y_test)
print(y_pred)
# In[10]:
from sklearn.metrics import r2_score
r2_score(y_test,y_pred)
import numpy as np
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[8]:
print(X)
# 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)
BINOMIAL LOGISTIC REGRESSION
#k-nearest-neighbours(knn)
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# In[9]:
myfile="D:\BD_dataset\week3_Social_Network_Ads.csv"
dataset=pd.read_csv(myfile)
x=dataset.iloc[:,:-1].values
y=dataset.iloc[:,-1].values
#Splitting the dataset into the training set and test set
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x,y,test_size =
0.20, random_state = 0)
print(x_train)
# In[21]:
print(y_test)
#Feature Scaling
from sklearn.preprocessing import StandardScaler
sc=StandardScaler()
x_train = sc.fit_transform(x_train)
x_test = sc.transform(x_test)
print(x_train)
# In[23]:
print(x_test)
# In[12]:
myfile="D:\BD_dataset\week3_Social_Network_Ads.csv"
dataset=pd.read_csv(myfile)
x=dataset.iloc[:,:-1].values
y=dataset.iloc[:,-1].values
#Splitting the dataset into the training set and test set
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x,y,test_size =
0.20, random_state = 0)
print(x_train)
# In[14]:
print(y_test)
#Feature Scaling
from sklearn.preprocessing import StandardScaler
sc=StandardScaler()
x_train = sc.fit_transform(x_train)
x_test = sc.transform(x_test)
print(x_train)
# In[16]:
print(x_test)
#DecisionTreeClassifier
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# In[20]:
myfile="D:\BD_dataset\week3_Social_Network_Ads.csv"
dataset=pd.read_csv(myfile)
x=dataset.iloc[:,:-1].values
y=dataset.iloc[:,-1].values
#Splitting the dataset into the training set and test set
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x,y,test_size =
0.20, random_state = 0)
print(x_train)
# In[22]:
print(y_test)
#Feature Scaling
from sklearn.preprocessing import StandardScaler
sc=StandardScaler()
x_train = sc.fit_transform(x_train)
x_test = sc.transform(x_test)
print(x_train)
# In[24]:
print(x_test)
#DecisionTreeClassifier
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# In[46]:
myfile="D:\BD_dataset\week3_Social_Network_Ads.csv"
dataset=pd.read_csv(myfile)
x=dataset.iloc[:,:-1].values
y=dataset.iloc[:,-1].values
#Splitting the dataset into the training set and test set
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x,y,test_size =
0.20, random_state = 0)
print(x_train)
# In[48]:
print(y_test)
#Feature Scaling
from sklearn.preprocessing import StandardScaler
sc=StandardScaler()
x_train = sc.fit_transform(x_train)
x_test = sc.transform(x_test)
print(x_train)
# In[50]:
print(x_test)
#k-nearest-neighbours(knn)
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# In[2]:
myfile="D:\BD_dataset\week3_Social_Network_Ads.csv"
dataset=pd.read_csv(myfile)
x=dataset.iloc[:,:-1].values
y=dataset.iloc[:,-1].values
#Splitting the dataset into the training set and test set
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x,y,test_size =
0.20, random_state = 0)
print(x_train)
# In[4]:
print(y_test)
#Feature Scaling
from sklearn.preprocessing import StandardScaler
sc=StandardScaler()
x_train = sc.fit_transform(x_train)
x_test = sc.transform(x_test)
print(x_train)
# In[6]:
print(x_test)
mydatafile = "week3_social_networks_ads.csv"
dataset = pd.read_csv(mydatafile)
x = dataset.iloc[:, :-1].values
y = dataset.iloc[:, -1].values
#print(x_train)
#print(y_train)
#print(x_test)
#print(y_test)
#print(x_train)
#print(x_test)
print(classifier.predict(sc.transform([[30, 87000]])))