mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-28 15:31:08 +00:00
197 lines
45 KiB
Plaintext
197 lines
45 KiB
Plaintext
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 1,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stderr",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"C:\\Users\\Satyam\\AppData\\Roaming\\Python\\Python35\\site-packages\\sklearn\\ensemble\\weight_boosting.py:29: DeprecationWarning: numpy.core.umath_tests is an internal NumPy module and should not be imported. It will be removed in a future NumPy release.\n",
|
||
|
" from numpy.core.umath_tests import inner1d\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# Importing the libraries\n",
|
||
|
"import numpy as np\n",
|
||
|
"import matplotlib.pyplot as plt\n",
|
||
|
"import pandas as pd\n",
|
||
|
"from sklearn.model_selection import train_test_split\n",
|
||
|
"from sklearn.preprocessing import StandardScaler\n",
|
||
|
"from sklearn.metrics import confusion_matrix\n",
|
||
|
"from matplotlib.colors import ListedColormap\n",
|
||
|
"from sklearn.ensemble import RandomForestClassifier"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 2,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# Importing the dataset\n",
|
||
|
"dataset = pd.read_csv('Social_Network_Ads.csv')\n",
|
||
|
"X = dataset.iloc[:, [2, 3]].values\n",
|
||
|
"y = dataset.iloc[:, 4].values"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 3,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# Splitting the dataset into the Training set and Test set\n",
|
||
|
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 4,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stderr",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"C:\\Users\\Satyam\\AppData\\Roaming\\Python\\Python35\\site-packages\\sklearn\\utils\\validation.py:475: DataConversionWarning: Data with input dtype int64 was converted to float64 by StandardScaler.\n",
|
||
|
" warnings.warn(msg, DataConversionWarning)\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# Feature Scaling\n",
|
||
|
"sc = StandardScaler()\n",
|
||
|
"X_train = sc.fit_transform(X_train)\n",
|
||
|
"X_test = sc.transform(X_test)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 5,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"[[63 5]\n",
|
||
|
" [ 3 29]]\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# Fitting classifier to the Training set\n",
|
||
|
"# Create your classifier here\n",
|
||
|
"classifier = RandomForestClassifier(n_estimators=10,criterion='entropy',random_state=0)\n",
|
||
|
"classifier.fit(X_train,y_train)\n",
|
||
|
"# Predicting the Test set results\n",
|
||
|
"y_pred = classifier.predict(X_test)\n",
|
||
|
"\n",
|
||
|
"# Making the Confusion Matrix\n",
|
||
|
"cm = confusion_matrix(y_test, y_pred)\n",
|
||
|
"print(cm)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 6,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAEWCAYAAABmE+CbAAAABHNCSVQICAg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sw3o3nTsIfxzXAFt9FUJNlpKq/wQtyn+Wf9ySwErjJce6fgf/AW1V04wX6f112\nyguBO0WkD0/5vF+9PQTPwlPmT+F9Fz14QdOofAQvCeC3/lhvBTrrv6VC/gN4q883j+DeJT6BFzPp\nxRvj9TGuFQo/zvRavO/2Kby42E14KxUXLwJ+JyJ7gR8Cf6+qW1W1Fy9o/Wa8390O4LMM/Y6uBJ4v\nXgbdD/xjrwFuUdVuxhiiag1yDGM0IyJH4mWdnRwQeG4KROQe4D9V9bvDnjzyewjwO+Atqroxrfvk\nFTMIhmHkEt+duRFvdfU3eNly8/xMJyMFxuIuRMMwmoMFeGnOk4C/ABeaMUgXWyEYhmEYgAWVDcMw\nDJ+mchmNmzJOJxwxIWsxDGPU0Ffs45Q9yRbZvWdKHy2FFiaOS6XatjEC+h7u26WqRw53XlMZhAlH\nTODUT56atRiGMWpY+1AXd69N9m9q3JldTJ40hYUz61WsMBpJ19u6Hhn+LHMZGYZhGD5mEAzDMAzA\nDIJhGIbh01QxBMMwjCyY3DKZi+ZcxKyJsyjkdB49yCDb923n2q3X0jfQN6JrmEEwDMMYhovmXMSJ\nx5xI25Q2vOoW+UNVad/TzkVcxJUPXTmia+TT1BmGYeSIWRNn5doYAIgIbVPamDUxdKuPGswgGIZh\nDEOBQq6NQQkRieXSyswgiMgEEblLRP7gd5r6VFayGIZhGNmuEIrAWar6fLxmFOeJyIszlMcwDCPX\n3L7mds578Xmc+8JzWfm
|
||
|
"text/plain": [
|
||
|
"<matplotlib.figure.Figure at 0x14150b50>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAEWCAYAAABmE+CbAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XuYHGWZ9/HvPTPJJJqQxEAm4RDirBBR1KAoB8ObC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TJ3gk/aflHUyRMaNvv4+XrIj2Ylz/zi1j9aWViZP\nGBczaI8Lfff3PebuB4x2XEMFhEn7T+LoTx6ddTJExo2VG7q4fWWy/6cmnNDFlGdOZcHsBaMfLHXR\ndXbXA6MfpSojEREJKSCIiAiggCAiIqGGakMQEcnClNYpnDn3TOZMnkNLTp+jhxhi085NXLnxSvoG\n+8Z0DgUEEZFRnDn3TI48+Ejap7YTLD2RP+7OzB0zOZMzuXTDpWM6Rz5DnYhIjsyZPCfXwQDAzGif\n2s6cybGX7xhBAUFEZBQttOQ6GBSYWU1VWpkFBDObZGa3hgto321mn8oqLSIikm0JoR840d1fBCwA\nTjGzYzNMj4hIrv32xt9yyrGn8KqXvopLvnRJ4ufPLCCEy+QVmsInhH80F7eISITBwUE+/dFP880r\nv8m1v7uWn1/9c+5bd1+i18i0DcHMWs2sG9gC3ODut0Qcs9TMbjez2/fs2FP/RIqIVGnqj66h86gT\nOXzWEXQedSJTf3RNzee88447mTtvLofMO4SJEyfy2te/lhuvvzGB1O6TaUBw90F3XwAcDLzMzI6M\nOOYSdz/a3Y+eMHVC/RMpIlKFqT+6htkfvJAJDz2CuTPhoUeY/cELaw4KvZt6mXPQvh5Esw+cTe+m\n3lqTO0wuehm5+zbgZuC
|
||
|
"text/plain": [
|
||
|
"<matplotlib.figure.Figure at 0x14717ff0>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# Visualising the Training set results\n",
|
||
|
"X_set, y_set = X_train, y_train\n",
|
||
|
"X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 1, stop = X_set[:, 0].max() + 1, step = 0.01),\n",
|
||
|
" np.arange(start = X_set[:, 1].min() - 1, stop = X_set[:, 1].max() + 1, step = 0.01))\n",
|
||
|
"plt.contourf(X1, X2, classifier.predict(np.array([X1.ravel(), X2.ravel()]).T).reshape(X1.shape),\n",
|
||
|
" alpha = 0.75, cmap = ListedColormap(('red', 'green')))\n",
|
||
|
"plt.xlim(X1.min(), X1.max())\n",
|
||
|
"plt.ylim(X2.min(), X2.max())\n",
|
||
|
"for i, j in enumerate(np.unique(y_set)):\n",
|
||
|
" plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1],\n",
|
||
|
" c = ListedColormap(('red', 'green'))(i), label = j)\n",
|
||
|
"plt.title('Random Forest Classifier (Training set)')\n",
|
||
|
"plt.xlabel('Age')\n",
|
||
|
"plt.ylabel('Estimated Salary')\n",
|
||
|
"plt.legend()\n",
|
||
|
"plt.show()\n",
|
||
|
"\n",
|
||
|
"# Visualising the Test set results\n",
|
||
|
"X_set, y_set = X_test, y_test\n",
|
||
|
"X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 1, stop = X_set[:, 0].max() + 1, step = 0.01),\n",
|
||
|
" np.arange(start = X_set[:, 1].min() - 1, stop = X_set[:, 1].max() + 1, step = 0.01))\n",
|
||
|
"plt.contourf(X1, X2, classifier.predict(np.array([X1.ravel(), X2.ravel()]).T).reshape(X1.shape),\n",
|
||
|
" alpha = 0.75, cmap = ListedColormap(('red', 'green')))\n",
|
||
|
"plt.xlim(X1.min(), X1.max())\n",
|
||
|
"plt.ylim(X2.min(), X2.max())\n",
|
||
|
"for i, j in enumerate(np.unique(y_set)):\n",
|
||
|
" plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1],\n",
|
||
|
" c = ListedColormap(('red', 'green'))(i), label = j)\n",
|
||
|
"plt.title('Random Forest Classifier (Test set)')\n",
|
||
|
"plt.xlabel('Age')\n",
|
||
|
"plt.ylabel('Estimated Salary')\n",
|
||
|
"plt.legend()\n",
|
||
|
"plt.show()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {
|
||
|
"collapsed": true
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": []
|
||
|
}
|
||
|
],
|
||
|
"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.1"
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 2
|
||
|
}
|