Last active
July 17, 2017 20:01
-
-
Save vb100/733ae0df3e18eadc3b5e38756c6d5dbb to your computer and use it in GitHub Desktop.
Polynomial Regression Template for Machine learning in Python programming language. Prediction calculation.
This file contains hidden or 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
# Regression template | |
# Importing the Libraries | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import pandas as pd | |
# Importing the dataset | |
dataset = pd.read_csv('Data.csv') | |
X = dataset.iloc[:, 1:2].values | |
y = dataset.iloc[:, 2].values | |
# Splitting the dataset into the Training set and Test set | |
""""from sklearn.cross_validation import train_test_split | |
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)"""" | |
# Feature Scaling | |
""""from sklearn.preprocessing import StandardScaler | |
sc_X = StandardScaler() | |
X_train = sc_X.fit_transform(X_train) | |
X_test = sc_X.transform(X_test) | |
sc_y = StandardScaler() | |
y_train = sc_y.fit_transform(y_train)"""" | |
# Fitting the Regression Model to the dataset | |
# Create your regressor here | |
# Predicting a new result | |
y_pred = regressor.predict(6.5) | |
# Visualising the Regression results | |
plt.scatter(X, y, color = 'red') | |
plt.plot(X, regressor.predict(X), color = 'blue') | |
plt.title('Truth or Bluff (Regression Model)') | |
plt.xlabel('Independence variable (X)') | |
plt.ylabel('Dependence variable (y)') | |
plt.show() | |
# Visualising the Regression results (for higher resolution and smooth curve) | |
X_grid = np.arange(min(X), max(X), 0.1) # It a Numpy matrice | |
X_grid = X_grid.reshape((len(X_grid), 1)) # Reshape | |
plt.scatter(X, y, color = 'red') | |
plt.plot(X_grid, regressor.predict(X_grid), color = 'blue') | |
plt.title('Truth or Bluff (Regression Model)') | |
plt.xlabel('Independence variable (X)') | |
plt.ylabel('Dependence variable (y)') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment