This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Step 1 Load Data | |
import pandas as pd | |
dataset = pd.read_csv('Salary_Data.csv') | |
X = dataset.iloc[:, :-1].values | |
y = dataset.iloc[:,1].values |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Step 2: Split data into training and testing | |
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_state=0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Step 3: Fit Simple Linear Regression to Training Data | |
from sklearn.linear_model import LinearRegression | |
regressor = LinearRegression() | |
regressor.fit(X_train, y_train) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Step 4: Make Prediction | |
y_pred = regressor.predict(X_test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Step 5 - Visualize training set results | |
import matplotlib.pyplot as plt | |
# plot the actual data points of training set | |
plt.scatter(X_train, y_train, color = 'red') | |
# plot the regression line | |
plt.plot(X_train, regressor.predict(X_train), color='blue') | |
plt.title('Salary vs Experience (Training set)') | |
plt.xlabel('Years of Experience') | |
plt.ylabel('Salary') | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Step 6 - Visualize test set results | |
import matplotlib.pyplot as plt | |
# plot the actual data points of test set | |
plt.scatter(X_test, y_test, color = 'red') | |
# plot the regression line (same as above) | |
plt.plot(X_train, regressor.predict(X_train), color='blue') | |
plt.title('Salary vs Experience (Test set)') | |
plt.xlabel('Years of Experience') | |
plt.ylabel('Salary') | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Step 7 - Make new prediction | |
new_salary_pred = regressor.predict([[15]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
""" | |
Created on Sun Sep 1 19:14:35 2019 | |
@author: omairaasim | |
""" | |
# Step 1 Load Data | |
import pandas as pd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Step 1 - Load Data | |
import pandas as pd | |
dataset = pd.read_csv("50_Startups.csv") | |
X = dataset.iloc[:,:-1].values | |
y = dataset.iloc[:,4].values |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Step 2 - Encode Categorical Data | |
from sklearn.preprocessing import OneHotEncoder | |
from sklearn.compose import ColumnTransformer | |
import numpy as np | |
ct = ColumnTransformer(transformers=[('encoder',OneHotEncoder(),[3])], remainder='passthrough') | |
X = np.array(ct.fit_transform(X)) |
OlderNewer