Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
lazy-programmer-courses
/
numpy-stack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
3caf7456
authored
Jul 30, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Section 7 is finished
parent
4cbd5423
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
1019 additions
and
0 deletions
section_7_machine_learning/1_classification.ipynb
section_7_machine_learning/2_regression.ipynb
section_7_machine_learning/1_classification.ipynb
0 → 100644
View file @
3caf7456
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"from sklearn.datasets import load_breast_cancer\n",
"from sklearn.model_selection import train_test_split\n",
"from sklearn.ensemble import RandomForestClassifier\n",
"from sklearn.neural_network import MLPClassifier\n",
"from sklearn.preprocessing import StandardScaler"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"data = load_breast_cancer()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"sklearn.utils.Bunch"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(data)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"dict_keys(['data', 'feature_names', 'DESCR', 'target', 'target_names'])"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.keys()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[1.799e+01, 1.038e+01, 1.228e+02, ..., 2.654e-01, 4.601e-01,\n",
" 1.189e-01],\n",
" [2.057e+01, 1.777e+01, 1.329e+02, ..., 1.860e-01, 2.750e-01,\n",
" 8.902e-02],\n",
" [1.969e+01, 2.125e+01, 1.300e+02, ..., 2.430e-01, 3.613e-01,\n",
" 8.758e-02],\n",
" ...,\n",
" [1.660e+01, 2.808e+01, 1.083e+02, ..., 1.418e-01, 2.218e-01,\n",
" 7.820e-02],\n",
" [2.060e+01, 2.933e+01, 1.401e+02, ..., 2.650e-01, 4.087e-01,\n",
" 1.240e-01],\n",
" [7.760e+00, 2.454e+01, 4.792e+01, ..., 0.000e+00, 2.871e-01,\n",
" 7.039e-02]])"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.data"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(569, 30)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.data.shape"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,\n",
" 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,\n",
" 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0,\n",
" 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0,\n",
" 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1,\n",
" 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0,\n",
" 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,\n",
" 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1,\n",
" 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0,\n",
" 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0,\n",
" 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1,\n",
" 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
" 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1,\n",
" 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1,\n",
" 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0,\n",
" 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0,\n",
" 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0,\n",
" 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1,\n",
" 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0,\n",
" 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1,\n",
" 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0,\n",
" 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1,\n",
" 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1,\n",
" 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,\n",
" 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
" 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1])"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.target"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array(['malignant', 'benign'], dtype='<U9')"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.target_names"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array(['mean radius', 'mean texture', 'mean perimeter', 'mean area',\n",
" 'mean smoothness', 'mean compactness', 'mean concavity',\n",
" 'mean concave points', 'mean symmetry', 'mean fractal dimension',\n",
" 'radius error', 'texture error', 'perimeter error', 'area error',\n",
" 'smoothness error', 'compactness error', 'concavity error',\n",
" 'concave points error', 'symmetry error',\n",
" 'fractal dimension error', 'worst radius', 'worst texture',\n",
" 'worst perimeter', 'worst area', 'worst smoothness',\n",
" 'worst compactness', 'worst concavity', 'worst concave points',\n",
" 'worst symmetry', 'worst fractal dimension'], dtype='<U23')"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.feature_names"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"X_train, X_test, Y_train, Y_test = train_test_split(data.data, data.target, test_size=0.33)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"model = RandomForestClassifier()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',\n",
" max_depth=None, max_features='auto', max_leaf_nodes=None,\n",
" min_impurity_decrease=0.0, min_impurity_split=None,\n",
" min_samples_leaf=1, min_samples_split=2,\n",
" min_weight_fraction_leaf=0.0, n_estimators=10, n_jobs=1,\n",
" oob_score=False, random_state=None, verbose=0,\n",
" warm_start=False)"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model.fit(X_train, Y_train)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.9921259842519685"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model.score(X_train, Y_train)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.9361702127659575"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model.score(X_test, Y_test)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0,\n",
" 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1,\n",
" 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1,\n",
" 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0,\n",
" 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0,\n",
" 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1,\n",
" 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0,\n",
" 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0,\n",
" 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0])"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"predictions = model.predict(X_test)\n",
"predictions"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"188"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"N = len(Y_test)\n",
"N"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"176"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"corr = np.sum(predictions == Y_test)\n",
"corr"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.9361702127659575"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"accuracy = corr / N\n",
"accuracy"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"scaler = StandardScaler()"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"X_train2 = scaler.fit_transform(X_train)\n",
"X_test2 = scaler.transform(X_test)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"MLPClassifier(activation='relu', alpha=0.0001, batch_size='auto', beta_1=0.9,\n",
" beta_2=0.999, early_stopping=False, epsilon=1e-08,\n",
" hidden_layer_sizes=(100,), learning_rate='constant',\n",
" learning_rate_init=0.001, max_iter=500, momentum=0.9,\n",
" nesterovs_momentum=True, power_t=0.5, random_state=None,\n",
" shuffle=True, solver='adam', tol=0.0001, validation_fraction=0.1,\n",
" verbose=False, warm_start=False)"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model = MLPClassifier(max_iter=500)\n",
"model.fit(X_train2, Y_train)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.9973753280839895"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model.score(X_train2, Y_train)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.973404255319149"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model.score(X_test2, Y_test)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
section_7_machine_learning/2_regression.ipynb
0 → 100644
View file @
3caf7456
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.model_selection import train_test_split\n",
"from sklearn.linear_model import LinearRegression\n",
"from sklearn.ensemble import RandomForestRegressor"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv(\"airfoil_self_noise.csv\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>X1</th>\n",
" <th>X2</th>\n",
" <th>X3</th>\n",
" <th>X4</th>\n",
" <th>X5</th>\n",
" <th>X6</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>800</td>\n",
" <td>0.0</td>\n",
" <td>0.3048</td>\n",
" <td>71.3</td>\n",
" <td>0.002663</td>\n",
" <td>126.201</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1000</td>\n",
" <td>0.0</td>\n",
" <td>0.3048</td>\n",
" <td>71.3</td>\n",
" <td>0.002663</td>\n",
" <td>125.201</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>1250</td>\n",
" <td>0.0</td>\n",
" <td>0.3048</td>\n",
" <td>71.3</td>\n",
" <td>0.002663</td>\n",
" <td>125.951</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>1600</td>\n",
" <td>0.0</td>\n",
" <td>0.3048</td>\n",
" <td>71.3</td>\n",
" <td>0.002663</td>\n",
" <td>127.591</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2000</td>\n",
" <td>0.0</td>\n",
" <td>0.3048</td>\n",
" <td>71.3</td>\n",
" <td>0.002663</td>\n",
" <td>127.461</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" X1 X2 X3 X4 X5 X6\n",
"0 800 0.0 0.3048 71.3 0.002663 126.201\n",
"1 1000 0.0 0.3048 71.3 0.002663 125.201\n",
"2 1250 0.0 0.3048 71.3 0.002663 125.951\n",
"3 1600 0.0 0.3048 71.3 0.002663 127.591\n",
"4 2000 0.0 0.3048 71.3 0.002663 127.461"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n",
"RangeIndex: 1503 entries, 0 to 1502\n",
"Data columns (total 6 columns):\n",
"X1 1503 non-null int64\n",
"X2 1503 non-null float64\n",
"X3 1503 non-null float64\n",
"X4 1503 non-null float64\n",
"X5 1503 non-null float64\n",
"X6 1503 non-null float64\n",
"dtypes: float64(5), int64(1)\n",
"memory usage: 70.5 KB\n"
]
}
],
"source": [
"df.info()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(1503, 5)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data = df[['X1','X2','X3','X4','X5']].values\n",
"data.shape"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(1503,)"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"target = df['X6'].values\n",
"target.shape"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"X_train, X_test, Y_train, Y_test = train_test_split(data, target, test_size=0.33)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"model = LinearRegression()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False)"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model.fit(X_train, Y_train)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.5237469959106811"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model.score(X_train, Y_train)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.4974498527611476"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model.score(X_test, Y_test)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([128.85257061, 124.44095482, 126.70379557, 130.32925262,\n",
" 126.44802634, 128.93367839, 126.56215582, 128.82602036,\n",
" 127.50565845, 122.90124167, 120.57197331, 125.81136833,\n",
" 111.83542438, 122.41370522, 117.85104598, 131.27736225,\n",
" 121.4257048 , 127.18654957, 135.18625424, 122.40503788,\n",
" 125.95220045, 125.77796302, 126.74771891, 127.26785768,\n",
" 125.58268171, 120.14025652, 127.43151973, 121.57264672,\n",
" 115.82723253, 132.15186988, 121.60115683, 129.60070342,\n",
" 124.5947802 , 126.55736387, 133.17581518, 115.65713936,\n",
" 120.62732759, 114.84216987, 125.85950577, 119.47257429,\n",
" 123.86151054, 119.55695705, 125.66527385, 128.55083775,\n",
" 125.11834489, 129.51315847, 129.92746808, 121.14670104,\n",
" 129.73971326, 124.26219257, 126.31602837, 126.33425066,\n",
" 128.06526948, 117.12498494, 121.4877861 , 129.33395039,\n",
" 123.99399853, 118.56314331, 132.3934895 , 127.3320124 ,\n",
" 129.40324061, 125.46365279, 124.38089553, 115.24985805,\n",
" 121.05778888, 119.51784843, 126.22422885, 123.7634183 ,\n",
" 124.54150386, 121.82926558, 121.78162703, 129.38257739,\n",
" 125.04651258, 120.78951652, 120.47106317, 127.00336593,\n",
" 129.37093855, 131.36142451, 123.82589455, 126.94536772,\n",
" 120.84595837, 121.83852927, 113.98911679, 127.36293705,\n",
" 119.84751664, 129.49615457, 127.35108148, 130.79625275,\n",
" 124.22926582, 127.33308556, 133.25334674, 122.16777942,\n",
" 126.78028185, 121.82916142, 124.7901317 , 120.33505309,\n",
" 132.36999591, 113.03822227, 119.23063616, 130.98172826,\n",
" 126.37597141, 126.73746657, 131.85845956, 123.1548531 ,\n",
" 125.53801153, 124.14666812, 122.39634732, 126.59037021,\n",
" 120.62462026, 131.0303484 , 127.47558041, 128.78875274,\n",
" 131.59377877, 119.44523046, 131.96533178, 113.84036743,\n",
" 126.34362584, 131.62157937, 128.07001315, 124.32098876,\n",
" 123.99189338, 123.90743468, 118.94167612, 121.43225328,\n",
" 126.09790235, 128.8394831 , 113.5636191 , 119.0162074 ,\n",
" 122.98132019, 126.50224905, 116.69678426, 127.17724419,\n",
" 118.81146455, 131.77748329, 123.65139961, 117.20119141,\n",
" 135.21043392, 109.85312798, 125.64297597, 124.79773609,\n",
" 122.22394312, 132.27016021, 123.60696509, 123.99358138,\n",
" 123.63013957, 124.3358099 , 123.05655016, 127.97338221,\n",
" 124.02482012, 123.60907025, 129.13194962, 123.63989184,\n",
" 120.14915899, 122.53355066, 127.94170372, 125.50932751,\n",
" 131.41606903, 128.70662808, 128.34136971, 126.01706229,\n",
" 130.60592609, 128.43467171, 127.07527932, 126.44830086,\n",
" 119.81976353, 122.73577659, 120.70692341, 131.32870531,\n",
" 126.64773106, 126.16324389, 131.12539445, 123.13589012,\n",
" 128.00917669, 126.51003028, 112.68366947, 121.66455243,\n",
" 130.79510876, 124.91652469, 129.00855159, 115.95625742,\n",
" 128.80518496, 119.43310963, 127.21496557, 132.9276525 ,\n",
" 120.67325242, 124.9625359 , 119.28887903, 123.00659083,\n",
" 121.43106366, 120.89865874, 128.690524 , 130.01354372,\n",
" 133.11381862, 129.22705459, 124.67787504, 132.60795756,\n",
" 128.07551609, 129.09954231, 122.62166254, 127.84632327,\n",
" 123.84706445, 131.86817904, 123.85801787, 126.78217519,\n",
" 128.37676518, 110.80042286, 118.47974218, 115.95947454,\n",
" 131.79324316, 122.43187625, 123.59701425, 118.813994 ,\n",
" 123.91664205, 123.03353231, 124.95041507, 129.60831099,\n",
" 126.02790426, 125.70777401, 126.02245934, 127.73600976,\n",
" 127.29944945, 115.98933914, 125.99694131, 130.0905509 ,\n",
" 121.73794389, 128.66009228, 120.93814679, 121.98608511,\n",
" 125.47577362, 129.84930484, 119.6357778 , 128.81385056,\n",
" 129.9044807 , 124.34833259, 116.56795169, 128.33789446,\n",
" 123.82781098, 127.15834385, 128.72157102, 121.35164031,\n",
" 126.66400648, 122.24945373, 131.80020497, 122.18175302,\n",
" 122.80109758, 120.72712862, 124.61714387, 130.52263 ,\n",
" 120.05245854, 112.63648736, 130.32543888, 131.32486327,\n",
" 137.37563767, 121.15214596, 133.56290162, 124.0142446 ,\n",
" 130.64621245, 127.79327332, 124.81968281, 115.03917753,\n",
" 125.26472531, 125.33706897, 126.19632815, 130.60378861,\n",
" 124.37682167, 124.90201518, 131.25117374, 123.69679951,\n",
" 117.62085645, 129.61522924, 128.75129804, 124.30886793,\n",
" 124.44738138, 130.42999771, 124.87306521, 119.86905167,\n",
" 122.20210985, 123.06249941, 121.96208546, 119.03496825,\n",
" 116.86599505, 129.06407547, 125.52050992, 125.3195448 ,\n",
" 129.12248512, 135.50702781, 103.88947579, 130.23023715,\n",
" 126.66782782, 122.25748204, 117.58297041, 118.07556748,\n",
" 120.91011309, 119.28660725, 121.17315981, 119.4306868 ,\n",
" 129.77617127, 123.24517975, 119.59274657, 133.81736232,\n",
" 126.94708411, 131.32378464, 122.86357383, 122.92939516,\n",
" 135.17798817, 119.61429173, 131.08120022, 125.02558771,\n",
" 124.62141301, 127.68100035, 122.02010959, 122.83978857,\n",
" 126.98517298, 126.28765475, 120.95960968, 123.22450685,\n",
" 130.68685314, 133.33295631, 124.09467743, 126.52959288,\n",
" 120.16958801, 125.21081139, 122.04739161, 114.98550513,\n",
" 124.31266695, 120.99195827, 128.88642871, 127.9439603 ,\n",
" 133.50504493, 129.59056925, 127.37252849, 125.92485662,\n",
" 119.50106337, 116.16712337, 127.01558594, 126.46575867,\n",
" 128.26247729, 129.87938289, 127.86431919, 132.45428565,\n",
" 126.36797529, 133.89489388, 122.22202669, 118.79817716,\n",
" 135.19437738, 119.11378108, 131.36115105, 127.15189361,\n",
" 114.39763039, 132.4785695 , 125.96374954, 124.40520341,\n",
" 126.90995548, 125.71026232, 126.03103589, 125.96109195,\n",
" 122.19766653, 131.15765664, 122.17926472, 122.57714548,\n",
" 120.75144349, 131.3008058 , 115.29382971, 129.03783681,\n",
" 132.30727803, 121.92899167, 136.34916224, 126.30553697,\n",
" 121.3880154 , 128.84808692, 123.12887603, 124.08357658,\n",
" 125.97242849, 130.31768473, 126.75569313, 126.86268776,\n",
" 122.15955044, 127.94710077, 124.15312955, 120.93047227,\n",
" 121.06010896, 124.85404844, 120.07373078, 127.84286424,\n",
" 120.17775917, 125.11090527, 130.00015752, 121.37955527,\n",
" 121.38993183, 125.4837036 , 130.16109956, 130.03853957,\n",
" 123.76992266, 129.97549754, 122.86549027, 117.43111834,\n",
" 128.67215854, 122.56089208, 124.76410743, 122.47018542,\n",
" 114.36868622, 119.80554029, 123.08263077, 122.55196902,\n",
" 128.20371963, 109.52187209, 127.7291186 , 127.6263272 ,\n",
" 125.98464917, 125.30017577, 113.72535366, 128.04897686,\n",
" 120.27606697, 130.91439796, 125.84128349, 123.95323305,\n",
" 127.763942 , 125.87524956, 123.45087371, 124.12020281,\n",
" 129.87635588, 127.23529474, 130.82827925, 118.60536741,\n",
" 127.51049289, 129.26061006, 118.67360056, 123.13490026,\n",
" 123.39151911, 122.83946599, 126.88717733, 119.88363766,\n",
" 127.730271 , 129.17535385, 128.71962645, 133.91970635,\n",
" 116.72041868, 128.24488156, 126.70825425, 125.83729903,\n",
" 133.07633745, 123.33356986, 111.4655563 , 122.9675231 ,\n",
" 122.12314563, 127.07539354, 124.57210146, 123.19351617,\n",
" 129.99410318, 127.60066042, 132.38929723, 130.61215673,\n",
" 129.12595853, 124.84215645, 115.60372883, 126.75285477,\n",
" 112.46844544, 127.09446262, 134.10223384, 123.37681155,\n",
" 130.7251094 , 126.87505651, 129.83335527, 129.2374989 ,\n",
" 125.54901071, 120.3822352 , 124.40435015, 123.09619742,\n",
" 120.91887209, 127.19660011, 122.71126913, 116.79701671,\n",
" 121.43435457, 124.34081073, 132.26312652, 119.77568741,\n",
" 108.62768866, 130.71285163, 123.91677432, 125.22693599,\n",
" 120.35229037, 126.13449334, 127.47502499, 124.93791744,\n",
" 123.44202943, 123.13816189, 125.3835769 , 122.92694294,\n",
" 125.16982118, 115.55241525, 121.47286535, 125.87787449,\n",
" 120.35838254, 127.67627241, 119.21844725, 123.25668494])"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"predictions = model.predict(X_test)\n",
"predictions"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"model2 = RandomForestRegressor()"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"RandomForestRegressor(bootstrap=True, criterion='mse', max_depth=None,\n",
" max_features='auto', max_leaf_nodes=None,\n",
" min_impurity_decrease=0.0, min_impurity_split=None,\n",
" min_samples_leaf=1, min_samples_split=2,\n",
" min_weight_fraction_leaf=0.0, n_estimators=10, n_jobs=1,\n",
" oob_score=False, random_state=None, verbose=0, warm_start=False)"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model2.fit(X_train, Y_train)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.9837915099203915"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model2.score(X_train, Y_train)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.9114997121678354"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model2.score(X_test, Y_test)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment