Skip to content

Instantly share code, notes, and snippets.

View panicpotatoe's full-sized avatar

Nhan Tran panicpotatoe

  • The Boring Labs
  • Singapore
View GitHub Profile
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
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 12 18:19:23 2018
@author: Nhan Tran
"""
"""
y = b0 + b1*x1
y: dependent variable
# Predicting the Test set results
y_pred = regressor.predict(X_test)
# Predicting the result of 5 Years Experience
y_pred = regressor.predict(5)
# 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
# Fitting Simple Linear Regression to the Training set
from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
regressor.fit(X_train, y_train)
# 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)
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
# 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
import statistics as stats