Path: blob/master/Part 2 - Regression/Decision Tree Regression/regression_template.py
1009 views
# Regression Template12# Importing the libraries3import numpy as np4import matplotlib.pyplot as plt5import pandas as pd67# Importing the dataset8dataset = pd.read_csv('Position_Salaries.csv')9X = dataset.iloc[:, 1:2].values10y = dataset.iloc[:, 2].values1112# Splitting the dataset into the Training set and Test set13"""from sklearn.cross_validation import train_test_split14X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)"""1516# Feature Scaling17"""from sklearn.preprocessing import StandardScaler18sc_X = StandardScaler()19X_train = sc_X.fit_transform(X_train)20X_test = sc_X.transform(X_test)21sc_y = StandardScaler()22y_train = sc_y.fit_transform(y_train)"""2324# Fitting the Regression Model to the dataset25# Create your regressor here2627# Predicting a new result28y_pred = regressor.predict(6.5)2930# Visualising the Regression results31plt.scatter(X, y, color = 'red')32plt.plot(X, regressor.predict(X), color = 'blue')33plt.title('Truth or Bluff (Regression Model)')34plt.xlabel('Position level')35plt.ylabel('Salary')36plt.show()3738# Visualising the Regression results (for higher resolution and smoother curve)39X_grid = np.arange(min(X), max(X), 0.1)40X_grid = X_grid.reshape((len(X_grid), 1))41plt.scatter(X, y, color = 'red')42plt.plot(X_grid, regressor.predict(X_grid), color = 'blue')43plt.title('Truth or Bluff (Regression Model)')44plt.xlabel('Position level')45plt.ylabel('Salary')46plt.show()4748