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
import numpy as np | |
import matplotlib.pyplot as plt | |
import pandas as pd | |
# Importing the dataset | |
dataset = pd.read_csv('https://s3.us-west-2.amazonaws.com/public.gamelab.fun/dataset/position_salaries.csv') | |
X = dataset.iloc[:, 1:2].values | |
y = dataset.iloc[:, 2].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
# -*- coding: utf-8 -*- | |
""" | |
Created on Mon Nov 12 18:19:23 2018 | |
@author: Nhan Tran | |
""" | |
""" | |
y = b0 + b1*x1 | |
y: dependent variable |
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
# Predicting the Test set results | |
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
# Predicting the result of 5 Years Experience | |
y_pred = regressor.predict(5) |
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
# Visualizing the Training set results | |
viz_train = plt | |
viz_train.scatter(X_train, y_train, color='red') | |
viz_train.plot(X_train, regressor.predict(X_train), color='blue') | |
viz_train.title('Salary VS Experience (Training set)') | |
viz_train.xlabel('Year of Experience') | |
viz_train.ylabel('Salary') | |
viz_train.show() | |
# Visualizing the Test set results |
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
# Fitting Simple Linear Regression to the Training set | |
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
# 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=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
import numpy as np | |
import matplotlib.pyplot as plt | |
import pandas as pd | |
# Importing the dataset | |
dataset = pd.read_csv('salary_data.csv') | |
X = dataset.iloc[:, :-1].values #get a copy of dataset exclude last column | |
y = dataset.iloc[:, 1].values #get array of dataset in column 1st |
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
# Create data set for pizza prices in New York | |
dataset_ny = [1, 2, 3, 3, 5, 6, 7, 8, 9, 11, 66] | |
# Finding Mean, Median, and Mode for pizza prices in New York | |
mean_ny = stats.mean(dataset_ny) | |
median_ny = stats.median(dataset_ny) | |
mode_ny = stats.mode(dataset_ny) | |
# Create data set for pizza prices in Los Angeles | |
dataset_la = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | |
# Finding Mean, Median, and Mode for pizza prices in Los Angeles |
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
import statistics as stats |