예제 #1
0
# Importing the libraries
import statsmodels.api as sm
from sklearn.linear_model import LinearRegression
import sys
import os
import numpy as np
if '__file__' not in globals():
    sys.path.append(
        os.getcwd() +
        'Machine_Learning_A-Z_Mine/Part 2 - Regression/Section 5 - Multiple Linear Regression'
    )
import data_preprocessing_template as preprocessed_data

# %% codecell
# preprocess data
x_train, x_test, y_train, y_test, x, y = preprocessed_data.preprocess_data()

# %% codecell
# Fitting Simple Linear Regression to the Training set
regressor = LinearRegression()
regressor.fit(x_train, y_train)

# %% codecell
# Predicting the Test set results
y_pred = regressor.predict(x_test)

# %% codecell
# backwords elimination

# add constant to function
x = np.append(np.ones((50, 1), dtype=np.int), x, axis=1)
예제 #2
0
# Importing the libraries
import sys
import os
from sklearn.svm import SVC
from sklearn.metrics import confusion_matrix
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap
import numpy as np
if '__file__' not in globals():
    sys.path.append(os.getcwd() + '/Machine_Learning_A-Z_Mine/Part 3 - Classification/Section 16 - Support Vector Machine (SVM)')
import data_preprocessing_template as preprocessed_data


# %% codecell
# preprocess data
x_train, x_test, y_train, y_test, sc_x = preprocessed_data.preprocess_data()


# %% codecell
# Fitting SVM to the Training set
classifier = SVC(kernel="linear", random_state= 0)
classifier.fit(x_train, y_train)


# %% codecell
# Predicting the Test set results
y_pred = classifier.predict(x_test)


# %% codecell
# Making the Confusion Matrix
# Random Forest Regression

# %% codecell
# Importing the libraries
from sklearn.ensemble import RandomForestRegressor
import sys
import os
import matplotlib.pyplot as plt
import numpy as np
if '__file__' not in globals():
    sys.path.append(os.getcwd() + '/Machine_Learning_A-Z_Mine/Part 2 - Regression/Section 9 - Random Forest Regression')
import data_preprocessing_template as preprocessed_data

# %% codecell
# preprocess data
x, y = preprocessed_data.preprocess_data()

# %% codecell
# Fitting Random Forest Regression to dataset
regresor = RandomForestRegressor(criterion="mse", n_estimators=300, random_state=0)
regresor.fit(x, y.ravel())


# %% codecell
"""
# Visualising the Random Forest Regression results
plt.scatter(x, y, color='red')
plt.plot(x, regresor.predict(x), color='blue')
plt.title('Truth or Bluff (Decision Tree Regression)')
plt.xlabel('Position level')
plt.ylabel('Salary')
예제 #4
0
# Importing the libraries
from sklearn.svm import SVR
import sys
import os
import matplotlib.pyplot as plt
import numpy as np
if '__file__' not in globals():
    sys.path.append(
        os.getcwd() +
        '/Machine_Learning_A-Z_Mine/Part 2 - Regression/Section 7 - Support Vector Regression (SVR)'
    )
import data_preprocessing_template as preprocessed_data

# %% codecell
# preprocess data
x, y, sc_x, sc_y = preprocessed_data.preprocess_data()

# %% codecell
# Fitting SVR to dataset
regresor = SVR(kernel='rbf')
regresor.fit(x, y.ravel())

# %% codecell
# Visualising the SVR results
plt.scatter(x, y, color='red')
plt.plot(x, regresor.predict(x), color='blue')
plt.title('Truth or Bluff (SVR)')
plt.xlabel('Position level')
plt.ylabel('Salary')
plt.show()