├── day66-adaboost └── readme.md ├── day68-stacking ├── day65-random-forest ├── readme.md ├── oob-score-demo.ipynb └── heart.csv ├── day29-sklearn-pipelines ├── model │ ├── readme.md │ ├── clf.pkl │ ├── ohe_sex.pkl │ └── ohe_embarked.pkl ├── readme.md ├── pipe.pkl ├── predict-using-pipeline.ipynb └── predict-without-pipeline.ipynb ├── day39-knn-imputer ├── readme.md └── day39.ipynb ├── day51-gradient-descent ├── readme.md ├── animation.gif ├── animation1.gif ├── animation2.gif ├── animation3.gif ├── animation4.gif ├── animation5.gif ├── animation6.gif ├── animation7.gif ├── animation8.gif ├── animation9.gif └── gradient-descent-code-from-scratch.ipynb ├── day60-logistic-regression-contd ├── readme.md └── streamlit-viz-tool.py ├── day21-bivariate-analysis └── readme.md ├── day56-lasso-regression └── readme.md ├── day58-logistic-regression └── readme.md ├── gradient-boosting └── readme.md ├── day52-types-of-gradient-descent ├── readme.md ├── mini_batch_contour_plot.gif ├── stochastic_animation_cost_plot.gif ├── stochastic_animation_line_plot.gif ├── stochastic_animation_contour_plot.gif ├── batch-gradient-descent.ipynb ├── stochastic-gradient-descent-from-scratch.ipynb └── mini-batch-gradient-descent-from-scratch.ipynb ├── day55-regularized-linear-models ├── readme.md ├── ridge-regression-from-scratch.ipynb └── ridge-regression-gradient-descent.ipynb ├── day57-elasticnet-regression ├── readme.md └── elastic-net-regression.ipynb ├── day59-classification-metrics └── readme.md ├── day68-stacking-and-blending ├── readme1.md └── heart.csv ├── day37-handling-missing-categorical-data └── readme.md ├── day43-outlier-removal-using-iqr-method └── readme.md ├── day44-outlier-detection-using-percentiles └── readme.md ├── kmeans ├── readme.md ├── app.py ├── kmeans.py └── student_clustering.csv ├── day24-standardization ├── readme.md └── Social_Network_Ads.csv ├── day25-normalization ├── readme.md └── wine_data.csv ├── day26-ordinal-encoding ├── readme.md └── customer.csv ├── day27-one-hot-encoding └── readme.md ├── day38-missing-indicator └── readme.md ├── day28-column-transformer ├── readme.md ├── covid_toy.csv └── day28.ipynb ├── day30-function-transformer └── readme.md ├── day31-power-transformer └── readme.md ├── day40-iterative-imputer ├── readme.md └── 50_Startups.csv ├── day49-regression-metrics ├── readme.md └── placement.csv ├── day53-polynomial-regression └── readme.md ├── day32-binning-and-binarization └── readme.md ├── day33-handling-mixed-variables └── readme.md ├── day34-handling-date-and-time └── readme.md ├── day35-complete-case-analysis └── readme.md ├── day36-imputing-numerical-data └── readme.md ├── day42-outlier-removal-using-zscore └── readme.md ├── day48-simple-linear-regression ├── readme.md ├── placement.csv └── Untitled1.ipynb ├── day50-multiple-linear-regression ├── readme.md └── code-from-scratch.ipynb ├── day22-pandas-profiling └── readme.md ├── day20-univariate-analysis └── readme.md ├── day45-feature-construction-and-feature-splitting └── readme.md ├── day18-pandas-dataframe-using-web-scraping └── readme.md ├── day19-understanding-your-data-descriptive-stats └── readme.md ├── day47-pca └── readme.md ├── day15 - working with csv files ├── zomato.csv ├── readme.md └── test.csv ├── day17-api-to-dataframe └── readme.md └── day16 - working-with-json-and-sql └── readme.md /day66-adaboost/readme.md: -------------------------------------------------------------------------------- 1 | Nothing 2 | -------------------------------------------------------------------------------- /day68-stacking: -------------------------------------------------------------------------------- 1 | nothing to display 2 | -------------------------------------------------------------------------------- /day65-random-forest/readme.md: -------------------------------------------------------------------------------- 1 | Nothing 2 | -------------------------------------------------------------------------------- /day29-sklearn-pipelines/model/readme.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /day39-knn-imputer/readme.md: -------------------------------------------------------------------------------- 1 | Video Link: 2 | -------------------------------------------------------------------------------- /day51-gradient-descent/readme.md: -------------------------------------------------------------------------------- 1 | Video Link 2 | -------------------------------------------------------------------------------- /day60-logistic-regression-contd/readme.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /day21-bivariate-analysis/readme.md: -------------------------------------------------------------------------------- 1 | Video link: 2 | -------------------------------------------------------------------------------- /day56-lasso-regression/readme.md: -------------------------------------------------------------------------------- 1 | Video Link: 2 | -------------------------------------------------------------------------------- /day58-logistic-regression/readme.md: -------------------------------------------------------------------------------- 1 | Video Link 2 | -------------------------------------------------------------------------------- /gradient-boosting/readme.md: -------------------------------------------------------------------------------- 1 | Nothing to display 2 | -------------------------------------------------------------------------------- /day52-types-of-gradient-descent/readme.md: -------------------------------------------------------------------------------- 1 | Video Link: 2 | -------------------------------------------------------------------------------- /day55-regularized-linear-models/readme.md: -------------------------------------------------------------------------------- 1 | Video Link 2 | -------------------------------------------------------------------------------- /day57-elasticnet-regression/readme.md: -------------------------------------------------------------------------------- 1 | Video Link: 2 | -------------------------------------------------------------------------------- /day59-classification-metrics/readme.md: -------------------------------------------------------------------------------- 1 | Video Link: 2 | -------------------------------------------------------------------------------- /day68-stacking-and-blending/readme1.md: -------------------------------------------------------------------------------- 1 | Nothing to display 2 | -------------------------------------------------------------------------------- /day37-handling-missing-categorical-data/readme.md: -------------------------------------------------------------------------------- 1 | Video Link 2 | -------------------------------------------------------------------------------- /day43-outlier-removal-using-iqr-method/readme.md: -------------------------------------------------------------------------------- 1 | Video Link: 2 | -------------------------------------------------------------------------------- /day44-outlier-detection-using-percentiles/readme.md: -------------------------------------------------------------------------------- 1 | Video Link : 2 | -------------------------------------------------------------------------------- /kmeans/readme.md: -------------------------------------------------------------------------------- 1 | Codes related to the K-Means clustering algorithm 2 | -------------------------------------------------------------------------------- /day24-standardization/readme.md: -------------------------------------------------------------------------------- 1 | Video Link : https://youtu.be/1Yw9sC0PNwY 2 | -------------------------------------------------------------------------------- /day25-normalization/readme.md: -------------------------------------------------------------------------------- 1 | Video Link: https://youtu.be/eBrGyuA2MIg 2 | -------------------------------------------------------------------------------- /day26-ordinal-encoding/readme.md: -------------------------------------------------------------------------------- 1 | Video Link: https://youtu.be/w2GglmYHfmM 2 | -------------------------------------------------------------------------------- /day27-one-hot-encoding/readme.md: -------------------------------------------------------------------------------- 1 | Video Link : https://youtu.be/U5oCv3JKWKA 2 | -------------------------------------------------------------------------------- /day38-missing-indicator/readme.md: -------------------------------------------------------------------------------- 1 | Video Link:https://youtu.be/Ratcir3p03w 2 | -------------------------------------------------------------------------------- /day28-column-transformer/readme.md: -------------------------------------------------------------------------------- 1 | Video Link : https://youtu.be/5TVj6iEBR4I 2 | -------------------------------------------------------------------------------- /day29-sklearn-pipelines/readme.md: -------------------------------------------------------------------------------- 1 | Video Link : https://youtu.be/xOccYkgRV4Q 2 | -------------------------------------------------------------------------------- /day30-function-transformer/readme.md: -------------------------------------------------------------------------------- 1 | Video Link : https://youtu.be/cTjj3LE8E90 2 | -------------------------------------------------------------------------------- /day31-power-transformer/readme.md: -------------------------------------------------------------------------------- 1 | Video Link : https://youtu.be/lV_Z4HbNAx0 2 | -------------------------------------------------------------------------------- /day40-iterative-imputer/readme.md: -------------------------------------------------------------------------------- 1 | Video Link : https://youtu.be/a38ehxv3kyk 2 | -------------------------------------------------------------------------------- /day49-regression-metrics/readme.md: -------------------------------------------------------------------------------- 1 | Video Link: https://youtu.be/Ti7c-Hz7GSM 2 | -------------------------------------------------------------------------------- /day53-polynomial-regression/readme.md: -------------------------------------------------------------------------------- 1 | Video Link https://youtu.be/BNWLf3cKdbQ 2 | -------------------------------------------------------------------------------- /day32-binning-and-binarization/readme.md: -------------------------------------------------------------------------------- 1 | Video Link: https://youtu.be/kKWsJGKcMvo 2 | -------------------------------------------------------------------------------- /day33-handling-mixed-variables/readme.md: -------------------------------------------------------------------------------- 1 | Video Link : https://youtu.be/9xiX-I5_LQY 2 | -------------------------------------------------------------------------------- /day34-handling-date-and-time/readme.md: -------------------------------------------------------------------------------- 1 | Video Link : https://youtu.be/J73mvgG9fFs 2 | -------------------------------------------------------------------------------- /day35-complete-case-analysis/readme.md: -------------------------------------------------------------------------------- 1 | Video Link : https://youtu.be/aUnNWZorGmk 2 | -------------------------------------------------------------------------------- /day36-imputing-numerical-data/readme.md: -------------------------------------------------------------------------------- 1 | Video Link : https://youtu.be/mCL2xLBDw8M 2 | -------------------------------------------------------------------------------- /day42-outlier-removal-using-zscore/readme.md: -------------------------------------------------------------------------------- 1 | Video Link:https://youtu.be/OnPE-Z8jtqM 2 | -------------------------------------------------------------------------------- /day48-simple-linear-regression/readme.md: -------------------------------------------------------------------------------- 1 | Video Link : https://youtu.be/UZPfbG0jNec 2 | -------------------------------------------------------------------------------- /day50-multiple-linear-regression/readme.md: -------------------------------------------------------------------------------- 1 | Video Link : https://youtu.be/ashGekqstl8 2 | -------------------------------------------------------------------------------- /day22-pandas-profiling/readme.md: -------------------------------------------------------------------------------- 1 | Video Link:https://www.youtube.com/watch?v=E69Lg2ZgOxg 2 | -------------------------------------------------------------------------------- /day20-univariate-analysis/readme.md: -------------------------------------------------------------------------------- 1 | Video Link : https://www.youtube.com/watch?v=4HyTlbHUKSw 2 | -------------------------------------------------------------------------------- /day45-feature-construction-and-feature-splitting/readme.md: -------------------------------------------------------------------------------- 1 | Video Link https://youtu.be/ma-h30PoFms 2 | -------------------------------------------------------------------------------- /day18-pandas-dataframe-using-web-scraping/readme.md: -------------------------------------------------------------------------------- 1 | Video Link: https://www.youtube.com/watch?v=8NOdgjC1988 2 | -------------------------------------------------------------------------------- /day19-understanding-your-data-descriptive-stats/readme.md: -------------------------------------------------------------------------------- 1 | Video Link: https://www.youtube.com/watch?v=mJlRTUuVr04 2 | -------------------------------------------------------------------------------- /day47-pca/readme.md: -------------------------------------------------------------------------------- 1 | PCA code Kaggle notebook : https://www.kaggle.com/nitsin/pca-demo-1 2 | Video Link:https://youtu.be/tXXnxjj2wM4 3 | -------------------------------------------------------------------------------- /day29-sklearn-pipelines/pipe.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohanmistry231/100-days-of-machine-learning/main/day29-sklearn-pipelines/pipe.pkl -------------------------------------------------------------------------------- /day29-sklearn-pipelines/model/clf.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohanmistry231/100-days-of-machine-learning/main/day29-sklearn-pipelines/model/clf.pkl -------------------------------------------------------------------------------- /day51-gradient-descent/animation.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohanmistry231/100-days-of-machine-learning/main/day51-gradient-descent/animation.gif -------------------------------------------------------------------------------- /day51-gradient-descent/animation1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohanmistry231/100-days-of-machine-learning/main/day51-gradient-descent/animation1.gif -------------------------------------------------------------------------------- /day51-gradient-descent/animation2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohanmistry231/100-days-of-machine-learning/main/day51-gradient-descent/animation2.gif -------------------------------------------------------------------------------- /day51-gradient-descent/animation3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohanmistry231/100-days-of-machine-learning/main/day51-gradient-descent/animation3.gif -------------------------------------------------------------------------------- /day51-gradient-descent/animation4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohanmistry231/100-days-of-machine-learning/main/day51-gradient-descent/animation4.gif -------------------------------------------------------------------------------- /day51-gradient-descent/animation5.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohanmistry231/100-days-of-machine-learning/main/day51-gradient-descent/animation5.gif -------------------------------------------------------------------------------- /day51-gradient-descent/animation6.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohanmistry231/100-days-of-machine-learning/main/day51-gradient-descent/animation6.gif -------------------------------------------------------------------------------- /day51-gradient-descent/animation7.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohanmistry231/100-days-of-machine-learning/main/day51-gradient-descent/animation7.gif -------------------------------------------------------------------------------- /day51-gradient-descent/animation8.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohanmistry231/100-days-of-machine-learning/main/day51-gradient-descent/animation8.gif -------------------------------------------------------------------------------- /day51-gradient-descent/animation9.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohanmistry231/100-days-of-machine-learning/main/day51-gradient-descent/animation9.gif -------------------------------------------------------------------------------- /day15 - working with csv files/zomato.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohanmistry231/100-days-of-machine-learning/main/day15 - working with csv files/zomato.csv -------------------------------------------------------------------------------- /day29-sklearn-pipelines/model/ohe_sex.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohanmistry231/100-days-of-machine-learning/main/day29-sklearn-pipelines/model/ohe_sex.pkl -------------------------------------------------------------------------------- /day29-sklearn-pipelines/model/ohe_embarked.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohanmistry231/100-days-of-machine-learning/main/day29-sklearn-pipelines/model/ohe_embarked.pkl -------------------------------------------------------------------------------- /day15 - working with csv files/readme.md: -------------------------------------------------------------------------------- 1 | Video link : https://www.youtube.com/watch?v=a_XrmKlaGTs 2 | 3 | Books dataset link : http://www2.informatik.uni-freiburg.de/~cziegler/BX/ 4 | -------------------------------------------------------------------------------- /day52-types-of-gradient-descent/mini_batch_contour_plot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohanmistry231/100-days-of-machine-learning/main/day52-types-of-gradient-descent/mini_batch_contour_plot.gif -------------------------------------------------------------------------------- /day17-api-to-dataframe/readme.md: -------------------------------------------------------------------------------- 1 | Video Link: 2 | 3 | TMDB API : https://developers.themoviedb.org/ 4 | RapidAPI : https://rapidapi.com/collection/list-of-free-apis 5 | JSON Viewer: http://jsonviewer.stack.hu/ 6 | -------------------------------------------------------------------------------- /day52-types-of-gradient-descent/stochastic_animation_cost_plot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohanmistry231/100-days-of-machine-learning/main/day52-types-of-gradient-descent/stochastic_animation_cost_plot.gif -------------------------------------------------------------------------------- /day52-types-of-gradient-descent/stochastic_animation_line_plot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohanmistry231/100-days-of-machine-learning/main/day52-types-of-gradient-descent/stochastic_animation_line_plot.gif -------------------------------------------------------------------------------- /day52-types-of-gradient-descent/stochastic_animation_contour_plot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohanmistry231/100-days-of-machine-learning/main/day52-types-of-gradient-descent/stochastic_animation_contour_plot.gif -------------------------------------------------------------------------------- /day16 - working-with-json-and-sql/readme.md: -------------------------------------------------------------------------------- 1 | Video link: https://www.youtube.com/watch?v=fFwRC-fapIU 2 | 3 | Xampp download link: https://www.apachefriends.org/index.html 4 | World dataset : https://www.kaggle.com/busielmorley/worldcities-pop-lang-rank-sql-create-tbls?select=world.sql 5 | Pandas read_json documentation: https://pandas.pydata.org/docs/reference/api/pandas.read_json.html 6 | Pandas read_sql_query documentation: https://pandas.pydata.org/docs/reference/api/pandas.read_sql_query.html#pandas.read_sql_query 7 | -------------------------------------------------------------------------------- /day15 - working with csv files/test.csv: -------------------------------------------------------------------------------- 1 | ,,,,,,,,,,,,,, 2 | 0,enrollee_id,city,city_development_index,gender,relevent_experience,enrolled_university,education_level,major_discipline,experience,company_size,company_type,last_new_job,training_hours,target 3 | 1,29725,city_40,0.776,Male,No relevent experience,no_enrollment,Graduate,STEM,15,50-99,Pvt Ltd,>4,47,0 4 | 2,11561,city_21,0.624,NaN,No relevent experience,Full time course,Graduate,STEM,5,NaN,NaN,never,83,0 5 | 3,33241,city_115,0.789,NaN,No relevent experience,NaN,Graduate,Business Degree,<1,NaN,Pvt Ltd,never,52,1 6 | 4,666,city_162,0.767,Male,Has relevent experience,no_enrollment,Masters,STEM,>20,50-99,Funded Startup,4,8,0 -------------------------------------------------------------------------------- /kmeans/app.py: -------------------------------------------------------------------------------- 1 | from sklearn.datasets import make_blobs 2 | import matplotlib.pyplot as plt 3 | from kmeans import KMeans 4 | import pandas as pd 5 | 6 | #centroids = [(-5,-5),(5,5),(-2.5,2.5),(2.5,-2.5)] 7 | #cluster_std = [1,1,1,1] 8 | 9 | #X,y = make_blobs(n_samples=100,cluster_std=cluster_std,centers=centroids,n_features=2,random_state=2) 10 | 11 | #plt.scatter(X[:,0],X[:,1]) 12 | 13 | df = pd.read_csv('student_clustering.csv') 14 | 15 | X = df.iloc[:,:].values 16 | 17 | km = KMeans(n_clusters=4,max_iter=500) 18 | y_means = km.fit_predict(X) 19 | 20 | plt.scatter(X[y_means == 0,0],X[y_means == 0,1],color='red') 21 | plt.scatter(X[y_means == 1,0],X[y_means == 1,1],color='blue') 22 | plt.scatter(X[y_means == 2,0],X[y_means == 2,1],color='green') 23 | plt.scatter(X[y_means == 3,0],X[y_means == 3,1],color='yellow') 24 | plt.show() -------------------------------------------------------------------------------- /day26-ordinal-encoding/customer.csv: -------------------------------------------------------------------------------- 1 | age,gender,review,education,purchased 2 | 30,Female,Average,School,No 3 | 68,Female,Poor,UG,No 4 | 70,Female,Good,PG,No 5 | 72,Female,Good,PG,No 6 | 16,Female,Average,UG,No 7 | 31,Female,Average,School,Yes 8 | 18,Male,Good,School,No 9 | 60,Female,Poor,School,Yes 10 | 65,Female,Average,UG,No 11 | 74,Male,Good,UG,Yes 12 | 98,Female,Good,UG,Yes 13 | 74,Male,Good,UG,Yes 14 | 51,Male,Poor,School,No 15 | 57,Female,Average,School,No 16 | 15,Male,Poor,PG,Yes 17 | 75,Male,Poor,UG,No 18 | 59,Male,Poor,UG,Yes 19 | 22,Female,Poor,UG,Yes 20 | 19,Male,Good,School,No 21 | 97,Male,Poor,PG,Yes 22 | 57,Female,Average,School,Yes 23 | 32,Male,Average,PG,No 24 | 18,Female,Poor,PG,Yes 25 | 96,Female,Good,School,No 26 | 16,Female,Average,PG,Yes 27 | 57,Female,Good,School,No 28 | 53,Female,Poor,PG,No 29 | 69,Female,Poor,PG,No 30 | 48,Male,Poor,School,No 31 | 83,Female,Average,UG,Yes 32 | 73,Male,Average,UG,No 33 | 22,Female,Poor,School,Yes 34 | 92,Male,Average,UG,Yes 35 | 89,Female,Good,PG,Yes 36 | 86,Male,Average,School,No 37 | 74,Male,Poor,School,Yes 38 | 34,Female,Good,UG,Yes 39 | 94,Male,Average,PG,Yes 40 | 45,Female,Good,School,No 41 | 76,Male,Poor,PG,No 42 | 39,Male,Good,School,No 43 | 23,Male,Good,PG,Yes 44 | 30,Female,Good,PG,Yes 45 | 27,Male,Poor,PG,No 46 | 77,Female,Average,UG,No 47 | 61,Male,Poor,PG,Yes 48 | 64,Female,Poor,PG,No 49 | 38,Female,Good,PG,Yes 50 | 39,Female,Good,UG,Yes 51 | 25,Female,Good,UG,No 52 | -------------------------------------------------------------------------------- /kmeans/kmeans.py: -------------------------------------------------------------------------------- 1 | import random 2 | import numpy as np 3 | 4 | class KMeans: 5 | def __init__(self,n_clusters=2,max_iter=100): 6 | self.n_clusters = n_clusters 7 | self.max_iter = max_iter 8 | self.centroids = None 9 | 10 | def fit_predict(self,X): 11 | 12 | random_index = random.sample(range(0,X.shape[0]),self.n_clusters) 13 | self.centroids = X[random_index] 14 | 15 | for i in range(self.max_iter): 16 | # assign clusters 17 | cluster_group = self.assign_clusters(X) 18 | old_centroids = self.centroids 19 | # move centroids 20 | self.centroids = self.move_centroids(X,cluster_group) 21 | # check finish 22 | if (old_centroids == self.centroids).all(): 23 | break 24 | 25 | return cluster_group 26 | 27 | def assign_clusters(self,X): 28 | cluster_group = [] 29 | distances = [] 30 | 31 | for row in X: 32 | for centroid in self.centroids: 33 | distances.append(np.sqrt(np.dot(row-centroid,row-centroid))) 34 | min_distance = min(distances) 35 | index_pos = distances.index(min_distance) 36 | cluster_group.append(index_pos) 37 | distances.clear() 38 | 39 | return np.array(cluster_group) 40 | 41 | def move_centroids(self,X,cluster_group): 42 | new_centroids = [] 43 | 44 | cluster_type = np.unique(cluster_group) 45 | 46 | for type in cluster_type: 47 | new_centroids.append(X[cluster_group == type].mean(axis=0)) 48 | 49 | return np.array(new_centroids) 50 | 51 | -------------------------------------------------------------------------------- /day29-sklearn-pipelines/predict-using-pipeline.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 20, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "import pickle\n", 10 | "import numpy as np" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 21, 16 | "metadata": {}, 17 | "outputs": [], 18 | "source": [ 19 | "pipe = pickle.load(open('pipe.pkl','rb'))" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": 24, 25 | "metadata": {}, 26 | "outputs": [], 27 | "source": [ 28 | "# Assume user input\n", 29 | "test_input2 = np.array([2, 'male', 31.0, 0, 0, 10.5, 'S'],dtype=object).reshape(1,7)" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 25, 35 | "metadata": {}, 36 | "outputs": [ 37 | { 38 | "data": { 39 | "text/plain": [ 40 | "array([0], dtype=int64)" 41 | ] 42 | }, 43 | "execution_count": 25, 44 | "metadata": {}, 45 | "output_type": "execute_result" 46 | } 47 | ], 48 | "source": [ 49 | "pipe.predict(test_input2)" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": null, 55 | "metadata": {}, 56 | "outputs": [], 57 | "source": [] 58 | } 59 | ], 60 | "metadata": { 61 | "kernelspec": { 62 | "display_name": "Python 3", 63 | "language": "python", 64 | "name": "python3" 65 | }, 66 | "language_info": { 67 | "codemirror_mode": { 68 | "name": "ipython", 69 | "version": 3 70 | }, 71 | "file_extension": ".py", 72 | "mimetype": "text/x-python", 73 | "name": "python", 74 | "nbconvert_exporter": "python", 75 | "pygments_lexer": "ipython3", 76 | "version": "3.8.3" 77 | } 78 | }, 79 | "nbformat": 4, 80 | "nbformat_minor": 4 81 | } 82 | -------------------------------------------------------------------------------- /day40-iterative-imputer/50_Startups.csv: -------------------------------------------------------------------------------- 1 | R&D Spend,Administration,Marketing Spend,State,Profit 2 | 165349.2,136897.8,471784.1,New York,192261.83 3 | 162597.7,151377.59,443898.53,California,191792.06 4 | 153441.51,101145.55,407934.54,Florida,191050.39 5 | 144372.41,118671.85,383199.62,New York,182901.99 6 | 142107.34,91391.77,366168.42,Florida,166187.94 7 | 131876.9,99814.71,362861.36,New York,156991.12 8 | 134615.46,147198.87,127716.82,California,156122.51 9 | 130298.13,145530.06,323876.68,Florida,155752.6 10 | 120542.52,148718.95,311613.29,New York,152211.77 11 | 123334.88,108679.17,304981.62,California,149759.96 12 | 101913.08,110594.11,229160.95,Florida,146121.95 13 | 100671.96,91790.61,249744.55,California,144259.4 14 | 93863.75,127320.38,249839.44,Florida,141585.52 15 | 91992.39,135495.07,252664.93,California,134307.35 16 | 119943.24,156547.42,256512.92,Florida,132602.65 17 | 114523.61,122616.84,261776.23,New York,129917.04 18 | 78013.11,121597.55,264346.06,California,126992.93 19 | 94657.16,145077.58,282574.31,New York,125370.37 20 | 91749.16,114175.79,294919.57,Florida,124266.9 21 | 86419.7,153514.11,0,New York,122776.86 22 | 76253.86,113867.3,298664.47,California,118474.03 23 | 78389.47,153773.43,299737.29,New York,111313.02 24 | 73994.56,122782.75,303319.26,Florida,110352.25 25 | 67532.53,105751.03,304768.73,Florida,108733.99 26 | 77044.01,99281.34,140574.81,New York,108552.04 27 | 64664.71,139553.16,137962.62,California,107404.34 28 | 75328.87,144135.98,134050.07,Florida,105733.54 29 | 72107.6,127864.55,353183.81,New York,105008.31 30 | 66051.52,182645.56,118148.2,Florida,103282.38 31 | 65605.48,153032.06,107138.38,New York,101004.64 32 | 61994.48,115641.28,91131.24,Florida,99937.59 33 | 61136.38,152701.92,88218.23,New York,97483.56 34 | 63408.86,129219.61,46085.25,California,97427.84 35 | 55493.95,103057.49,214634.81,Florida,96778.92 36 | 46426.07,157693.92,210797.67,California,96712.8 37 | 46014.02,85047.44,205517.64,New York,96479.51 38 | 28663.76,127056.21,201126.82,Florida,90708.19 39 | 44069.95,51283.14,197029.42,California,89949.14 40 | 20229.59,65947.93,185265.1,New York,81229.06 41 | 38558.51,82982.09,174999.3,California,81005.76 42 | 28754.33,118546.05,172795.67,California,78239.91 43 | 27892.92,84710.77,164470.71,Florida,77798.83 44 | 23640.93,96189.63,148001.11,California,71498.49 45 | 15505.73,127382.3,35534.17,New York,69758.98 46 | 22177.74,154806.14,28334.72,California,65200.33 47 | 1000.23,124153.04,1903.93,New York,64926.08 48 | 1315.46,115816.21,297114.46,Florida,49490.75 49 | 0,135426.92,0,California,42559.73 50 | 542.05,51743.15,0,New York,35673.41 51 | 0,116983.8,45173.06,California,14681.4 -------------------------------------------------------------------------------- /day60-logistic-regression-contd/streamlit-viz-tool.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | import streamlit as st 3 | import numpy as np 4 | from sklearn.model_selection import train_test_split 5 | from sklearn.datasets import make_classification,make_blobs 6 | from sklearn.linear_model import LogisticRegression 7 | from sklearn.metrics import accuracy_score 8 | 9 | def load_initial_graph(dataset,ax): 10 | if dataset == "Binary": 11 | X, y = make_blobs(n_features=2, centers=2,random_state=6) 12 | ax.scatter(X.T[0], X.T[1], c=y, cmap='rainbow') 13 | return X,y 14 | elif dataset == "Multiclass": 15 | X,y = make_blobs(n_features=2, centers=3,random_state=2) 16 | ax.scatter(X.T[0], X.T[1], c=y, cmap='rainbow') 17 | return X,y 18 | 19 | def draw_meshgrid(): 20 | a = np.arange(start=X[:, 0].min() - 1, stop=X[:, 0].max() + 1, step=0.01) 21 | b = np.arange(start=X[:, 1].min() - 1, stop=X[:, 1].max() + 1, step=0.01) 22 | 23 | XX, YY = np.meshgrid(a, b) 24 | 25 | input_array = np.array([XX.ravel(), YY.ravel()]).T 26 | 27 | return XX, YY, input_array 28 | 29 | 30 | plt.style.use('fivethirtyeight') 31 | 32 | st.sidebar.markdown("# Logistic Regression Classifier") 33 | 34 | dataset = st.sidebar.selectbox( 35 | 'Select Dataset', 36 | ('Binary','Multiclass') 37 | ) 38 | 39 | penalty = st.sidebar.selectbox( 40 | 'Regularization', 41 | ('l2', 'l1','elasticnet','none') 42 | ) 43 | 44 | c_input = float(st.sidebar.number_input('C',value=1.0)) 45 | 46 | solver = st.sidebar.selectbox( 47 | 'Solver', 48 | ('newton-cg', 'lbfgs', 'liblinear', 'sag', 'saga') 49 | ) 50 | 51 | max_iter = int(st.sidebar.number_input('Max Iterations',value=100)) 52 | 53 | multi_class = st.sidebar.selectbox( 54 | 'Multi Class', 55 | ('auto', 'ovr', 'multinomial') 56 | ) 57 | 58 | l1_ratio = int(st.sidebar.number_input('l1 Ratio')) 59 | 60 | # Load initial graph 61 | fig, ax = plt.subplots() 62 | 63 | # Plot initial graph 64 | X,y = load_initial_graph(dataset,ax) 65 | X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42) 66 | orig = st.pyplot(fig) 67 | 68 | if st.sidebar.button('Run Algorithm'): 69 | orig.empty() 70 | 71 | clf = LogisticRegression(penalty=penalty,C=c_input,solver=solver,max_iter=max_iter,multi_class=multi_class,l1_ratio=l1_ratio) 72 | clf.fit(X_train,y_train) 73 | 74 | y_pred = clf.predict(X_test) 75 | 76 | XX, YY, input_array = draw_meshgrid() 77 | labels = clf.predict(input_array) 78 | 79 | ax.contourf(XX, YY, labels.reshape(XX.shape), alpha=0.5, cmap='rainbow') 80 | plt.xlabel("Col1") 81 | plt.ylabel("Col2") 82 | orig = st.pyplot(fig) 83 | st.subheader("Accuracy for Decision Tree " + str(round(accuracy_score(y_test, y_pred), 2))) 84 | -------------------------------------------------------------------------------- /kmeans/student_clustering.csv: -------------------------------------------------------------------------------- 1 | cgpa,iq 2 | 5.13,88 3 | 5.9,113 4 | 8.36,93 5 | 8.27,97 6 | 5.45,110 7 | 5.88,109 8 | 8.41,98 9 | 8.8,115 10 | 5.79,110 11 | 8.09,94 12 | 4.6,86 13 | 6.1,110 14 | 8.16,97 15 | 5.0,88 16 | 5.71,108 17 | 8.31,95 18 | 5.5,111 19 | 7.87,91 20 | 6.05,111 21 | 5.84,113 22 | 7.47,98 23 | 4.86,86 24 | 7.78,92 25 | 4.78,87 26 | 4.96,88 27 | 7.93,98 28 | 4.86,87 29 | 9.18,119 30 | 8.04,94 31 | 5.43,106 32 | 8.86,117 33 | 6.01,112 34 | 8.83,118 35 | 5.32,106 36 | 7.77,96 37 | 8.0,96 38 | 8.56,118 39 | 5.91,108 40 | 5.44,84 41 | 5.57,113 42 | 5.34,85 43 | 8.43,96 44 | 8.02,93 45 | 5.31,86 46 | 8.96,116 47 | 8.78,116 48 | 8.14,94 49 | 6.4,108 50 | 8.45,119 51 | 5.67,109 52 | 5.14,83 53 | 4.95,86 54 | 8.79,116 55 | 8.12,96 56 | 8.81,115 57 | 6.05,108 58 | 5.85,111 59 | 8.88,115 60 | 5.87,109 61 | 9.07,117 62 | 6.02,104 63 | 8.34,96 64 | 8.65,95 65 | 8.92,118 66 | 5.21,87 67 | 8.75,113 68 | 8.53,93 69 | 4.91,85 70 | 5.77,111 71 | 8.29,95 72 | 6.06,109 73 | 8.71,116 74 | 7.93,94 75 | 5.28,83 76 | 5.55,109 77 | 8.86,118 78 | 5.81,112 79 | 9.3,117 80 | 5.15,88 81 | 8.72,92 82 | 8.14,91 83 | 9.01,121 84 | 5.47,111 85 | 4.9,85 86 | 8.97,116 87 | 4.89,88 88 | 9.0,117 89 | 5.74,109 90 | 8.76,117 91 | 5.8,108 92 | 8.78,117 93 | 9.23,114 94 | 8.2,92 95 | 5.05,86 96 | 8.67,95 97 | 8.18,94 98 | 9.03,118 99 | 8.61,95 100 | 4.98,91 101 | 9.13,118 102 | 5.88,110 103 | 5.01,86 104 | 4.95,88 105 | 8.91,119 106 | 4.96,89 107 | 4.85,86 108 | 7.99,92 109 | 4.76,90 110 | 8.98,118 111 | 9.03,118 112 | 8.08,94 113 | 8.86,117 114 | 5.91,109 115 | 5.67,111 116 | 8.26,91 117 | 8.89,118 118 | 8.25,95 119 | 5.74,108 120 | 8.97,117 121 | 4.98,87 122 | 4.78,87 123 | 5.69,109 124 | 8.4,93 125 | 8.72,119 126 | 7.84,97 127 | 5.2,85 128 | 8.08,98 129 | 6.05,109 130 | 5.05,87 131 | 8.25,96 132 | 8.3,93 133 | 6.14,111 134 | 5.01,83 135 | 4.77,86 136 | 5.74,112 137 | 8.93,118 138 | 5.94,109 139 | 4.68,87 140 | 7.9,100 141 | 7.97,96 142 | 8.21,94 143 | 4.81,85 144 | 5.86,111 145 | 5.03,87 146 | 4.98,87 147 | 8.58,118 148 | 5.32,88 149 | 8.94,117 150 | 6.38,107 151 | 4.86,88 152 | 8.6,117 153 | 4.89,85 154 | 8.77,117 155 | 8.81,116 156 | 4.88,86 157 | 8.23,95 158 | 6.61,111 159 | 8.54,118 160 | 6.04,110 161 | 8.35,93 162 | 5.01,86 163 | 8.97,119 164 | 6.24,108 165 | 8.33,92 166 | 8.91,117 167 | 4.67,86 168 | 6.1,109 169 | 5.15,85 170 | 4.97,88 171 | 8.68,119 172 | 9.06,120 173 | 5.8,110 174 | 8.9,117 175 | 4.87,88 176 | 5.2,89 177 | 8.46,98 178 | 8.94,115 179 | 5.87,108 180 | 4.99,88 181 | 8.91,115 182 | 8.91,117 183 | 5.97,108 184 | 6.17,110 185 | 6.01,107 186 | 7.89,96 187 | 4.79,88 188 | 7.91,93 189 | 8.23,91 190 | 8.95,116 191 | 6.33,111 192 | 8.4,93 193 | 8.44,94 194 | 4.76,89 195 | 4.78,85 196 | 8.79,96 197 | 4.68,89 198 | 8.57,118 199 | 5.85,112 200 | 6.23,108 201 | 8.82,117 202 | -------------------------------------------------------------------------------- /day49-regression-metrics/placement.csv: -------------------------------------------------------------------------------- 1 | cgpa,package 2 | 6.89,3.26 3 | 5.12,1.98 4 | 7.82,3.25 5 | 7.42,3.67 6 | 6.94,3.57 7 | 7.89,2.99 8 | 6.73,2.6 9 | 6.75,2.48 10 | 6.09,2.31 11 | 8.31,3.51 12 | 5.32,1.86 13 | 6.61,2.6 14 | 8.94,3.65 15 | 6.93,2.89 16 | 7.73,3.42 17 | 7.25,3.23 18 | 6.84,2.35 19 | 5.38,2.09 20 | 6.94,2.98 21 | 7.48,2.83 22 | 7.28,3.16 23 | 6.85,2.93 24 | 6.14,2.3 25 | 6.19,2.48 26 | 6.53,2.71 27 | 7.28,3.65 28 | 8.31,3.42 29 | 5.42,2.16 30 | 5.94,2.24 31 | 7.15,3.49 32 | 7.36,3.26 33 | 8.1,3.89 34 | 6.96,3.08 35 | 6.35,2.73 36 | 7.34,3.42 37 | 6.87,2.87 38 | 5.99,2.84 39 | 5.9,2.43 40 | 8.62,4.36 41 | 7.43,3.33 42 | 9.38,4.02 43 | 6.89,2.7 44 | 5.95,2.54 45 | 7.66,2.76 46 | 5.09,1.86 47 | 7.87,3.58 48 | 6.07,2.26 49 | 5.84,3.26 50 | 8.63,4.09 51 | 8.87,4.62 52 | 9.58,4.43 53 | 9.26,3.79 54 | 8.37,4.11 55 | 6.47,2.61 56 | 6.86,3.09 57 | 8.2,3.39 58 | 5.84,2.74 59 | 6.6,1.94 60 | 6.92,3.09 61 | 7.56,3.31 62 | 5.61,2.19 63 | 5.48,1.61 64 | 6.34,2.09 65 | 9.16,4.25 66 | 7.36,2.92 67 | 7.6,3.81 68 | 5.11,1.63 69 | 6.51,2.89 70 | 7.56,2.99 71 | 7.3,2.94 72 | 5.79,2.35 73 | 7.47,3.34 74 | 7.78,3.62 75 | 8.44,4.03 76 | 6.85,3.44 77 | 6.97,3.28 78 | 6.94,3.15 79 | 8.99,4.6 80 | 6.59,2.21 81 | 7.18,3.0 82 | 7.63,3.44 83 | 6.1,2.2 84 | 5.58,2.17 85 | 8.44,3.49 86 | 4.26,1.53 87 | 4.79,1.48 88 | 7.61,2.77 89 | 8.09,3.55 90 | 4.73,1.48 91 | 6.42,2.72 92 | 7.11,2.66 93 | 6.22,2.14 94 | 7.9,4.0 95 | 6.79,3.08 96 | 5.83,2.42 97 | 6.63,2.79 98 | 7.11,2.61 99 | 5.98,2.84 100 | 7.69,3.83 101 | 6.61,3.24 102 | 7.95,4.14 103 | 6.71,3.52 104 | 5.13,1.37 105 | 7.05,3.0 106 | 7.62,3.74 107 | 6.66,2.82 108 | 6.13,2.19 109 | 6.33,2.59 110 | 7.76,3.54 111 | 7.77,4.06 112 | 8.18,3.76 113 | 5.42,2.25 114 | 8.58,4.1 115 | 6.94,2.37 116 | 5.84,1.87 117 | 8.35,4.21 118 | 9.04,3.33 119 | 7.12,2.99 120 | 7.4,2.88 121 | 7.39,2.65 122 | 5.23,1.73 123 | 6.5,3.02 124 | 5.12,2.01 125 | 5.1,2.3 126 | 6.06,2.31 127 | 7.33,3.16 128 | 5.91,2.6 129 | 6.78,3.11 130 | 7.93,3.34 131 | 7.29,3.12 132 | 6.68,2.49 133 | 6.37,2.01 134 | 5.84,2.48 135 | 6.05,2.58 136 | 7.2,2.83 137 | 6.1,2.6 138 | 5.64,2.1 139 | 7.14,3.13 140 | 7.91,3.89 141 | 7.19,2.4 142 | 7.91,3.15 143 | 6.76,3.18 144 | 6.93,3.04 145 | 4.85,1.54 146 | 6.17,2.42 147 | 5.84,2.18 148 | 6.07,2.46 149 | 5.66,2.21 150 | 7.57,3.4 151 | 8.28,3.67 152 | 6.3,2.73 153 | 6.12,2.76 154 | 7.37,3.08 155 | 7.94,3.99 156 | 7.08,2.85 157 | 6.98,3.09 158 | 7.38,3.13 159 | 6.47,2.7 160 | 5.95,3.04 161 | 8.71,4.08 162 | 7.13,2.93 163 | 7.3,3.33 164 | 5.53,2.55 165 | 8.93,3.91 166 | 9.06,3.82 167 | 8.21,4.08 168 | 8.6,3.98 169 | 8.13,3.6 170 | 8.65,3.52 171 | 9.31,4.37 172 | 6.22,2.87 173 | 8.01,3.76 174 | 6.93,2.51 175 | 6.75,2.56 176 | 7.32,2.99 177 | 7.04,3.5 178 | 6.29,3.23 179 | 7.09,3.64 180 | 8.15,3.63 181 | 7.14,3.03 182 | 6.19,2.72 183 | 8.22,3.89 184 | 5.88,2.08 185 | 7.28,2.72 186 | 7.88,3.14 187 | 6.31,3.18 188 | 7.84,3.47 189 | 6.26,2.44 190 | 7.35,3.08 191 | 8.11,4.06 192 | 6.19,2.69 193 | 7.28,3.48 194 | 8.25,3.75 195 | 4.57,1.94 196 | 7.89,3.67 197 | 6.93,2.46 198 | 5.89,2.57 199 | 7.21,3.24 200 | 7.63,3.96 201 | 6.22,2.33 202 | -------------------------------------------------------------------------------- /day48-simple-linear-regression/placement.csv: -------------------------------------------------------------------------------- 1 | cgpa,package 2 | 6.89,3.26 3 | 5.12,1.98 4 | 7.82,3.25 5 | 7.42,3.67 6 | 6.94,3.57 7 | 7.89,2.99 8 | 6.73,2.6 9 | 6.75,2.48 10 | 6.09,2.31 11 | 8.31,3.51 12 | 5.32,1.86 13 | 6.61,2.6 14 | 8.94,3.65 15 | 6.93,2.89 16 | 7.73,3.42 17 | 7.25,3.23 18 | 6.84,2.35 19 | 5.38,2.09 20 | 6.94,2.98 21 | 7.48,2.83 22 | 7.28,3.16 23 | 6.85,2.93 24 | 6.14,2.3 25 | 6.19,2.48 26 | 6.53,2.71 27 | 7.28,3.65 28 | 8.31,3.42 29 | 5.42,2.16 30 | 5.94,2.24 31 | 7.15,3.49 32 | 7.36,3.26 33 | 8.1,3.89 34 | 6.96,3.08 35 | 6.35,2.73 36 | 7.34,3.42 37 | 6.87,2.87 38 | 5.99,2.84 39 | 5.9,2.43 40 | 8.62,4.36 41 | 7.43,3.33 42 | 9.38,4.02 43 | 6.89,2.7 44 | 5.95,2.54 45 | 7.66,2.76 46 | 5.09,1.86 47 | 7.87,3.58 48 | 6.07,2.26 49 | 5.84,3.26 50 | 8.63,4.09 51 | 8.87,4.62 52 | 9.58,4.43 53 | 9.26,3.79 54 | 8.37,4.11 55 | 6.47,2.61 56 | 6.86,3.09 57 | 8.2,3.39 58 | 5.84,2.74 59 | 6.6,1.94 60 | 6.92,3.09 61 | 7.56,3.31 62 | 5.61,2.19 63 | 5.48,1.61 64 | 6.34,2.09 65 | 9.16,4.25 66 | 7.36,2.92 67 | 7.6,3.81 68 | 5.11,1.63 69 | 6.51,2.89 70 | 7.56,2.99 71 | 7.3,2.94 72 | 5.79,2.35 73 | 7.47,3.34 74 | 7.78,3.62 75 | 8.44,4.03 76 | 6.85,3.44 77 | 6.97,3.28 78 | 6.94,3.15 79 | 8.99,4.6 80 | 6.59,2.21 81 | 7.18,3.0 82 | 7.63,3.44 83 | 6.1,2.2 84 | 5.58,2.17 85 | 8.44,3.49 86 | 4.26,1.53 87 | 4.79,1.48 88 | 7.61,2.77 89 | 8.09,3.55 90 | 4.73,1.48 91 | 6.42,2.72 92 | 7.11,2.66 93 | 6.22,2.14 94 | 7.9,4.0 95 | 6.79,3.08 96 | 5.83,2.42 97 | 6.63,2.79 98 | 7.11,2.61 99 | 5.98,2.84 100 | 7.69,3.83 101 | 6.61,3.24 102 | 7.95,4.14 103 | 6.71,3.52 104 | 5.13,1.37 105 | 7.05,3.0 106 | 7.62,3.74 107 | 6.66,2.82 108 | 6.13,2.19 109 | 6.33,2.59 110 | 7.76,3.54 111 | 7.77,4.06 112 | 8.18,3.76 113 | 5.42,2.25 114 | 8.58,4.1 115 | 6.94,2.37 116 | 5.84,1.87 117 | 8.35,4.21 118 | 9.04,3.33 119 | 7.12,2.99 120 | 7.4,2.88 121 | 7.39,2.65 122 | 5.23,1.73 123 | 6.5,3.02 124 | 5.12,2.01 125 | 5.1,2.3 126 | 6.06,2.31 127 | 7.33,3.16 128 | 5.91,2.6 129 | 6.78,3.11 130 | 7.93,3.34 131 | 7.29,3.12 132 | 6.68,2.49 133 | 6.37,2.01 134 | 5.84,2.48 135 | 6.05,2.58 136 | 7.2,2.83 137 | 6.1,2.6 138 | 5.64,2.1 139 | 7.14,3.13 140 | 7.91,3.89 141 | 7.19,2.4 142 | 7.91,3.15 143 | 6.76,3.18 144 | 6.93,3.04 145 | 4.85,1.54 146 | 6.17,2.42 147 | 5.84,2.18 148 | 6.07,2.46 149 | 5.66,2.21 150 | 7.57,3.4 151 | 8.28,3.67 152 | 6.3,2.73 153 | 6.12,2.76 154 | 7.37,3.08 155 | 7.94,3.99 156 | 7.08,2.85 157 | 6.98,3.09 158 | 7.38,3.13 159 | 6.47,2.7 160 | 5.95,3.04 161 | 8.71,4.08 162 | 7.13,2.93 163 | 7.3,3.33 164 | 5.53,2.55 165 | 8.93,3.91 166 | 9.06,3.82 167 | 8.21,4.08 168 | 8.6,3.98 169 | 8.13,3.6 170 | 8.65,3.52 171 | 9.31,4.37 172 | 6.22,2.87 173 | 8.01,3.76 174 | 6.93,2.51 175 | 6.75,2.56 176 | 7.32,2.99 177 | 7.04,3.5 178 | 6.29,3.23 179 | 7.09,3.64 180 | 8.15,3.63 181 | 7.14,3.03 182 | 6.19,2.72 183 | 8.22,3.89 184 | 5.88,2.08 185 | 7.28,2.72 186 | 7.88,3.14 187 | 6.31,3.18 188 | 7.84,3.47 189 | 6.26,2.44 190 | 7.35,3.08 191 | 8.11,4.06 192 | 6.19,2.69 193 | 7.28,3.48 194 | 8.25,3.75 195 | 4.57,1.94 196 | 7.89,3.67 197 | 6.93,2.46 198 | 5.89,2.57 199 | 7.21,3.24 200 | 7.63,3.96 201 | 6.22,2.33 202 | -------------------------------------------------------------------------------- /day28-column-transformer/covid_toy.csv: -------------------------------------------------------------------------------- 1 | age,gender,fever,cough,city,has_covid 2 | 60,Male,103.0,Mild,Kolkata,No 3 | 27,Male,100.0,Mild,Delhi,Yes 4 | 42,Male,101.0,Mild,Delhi,No 5 | 31,Female,98.0,Mild,Kolkata,No 6 | 65,Female,101.0,Mild,Mumbai,No 7 | 84,Female,,Mild,Bangalore,Yes 8 | 14,Male,101.0,Strong,Bangalore,No 9 | 20,Female,,Strong,Mumbai,Yes 10 | 19,Female,100.0,Strong,Bangalore,No 11 | 64,Female,101.0,Mild,Delhi,No 12 | 75,Female,,Mild,Delhi,No 13 | 65,Female,98.0,Mild,Mumbai,Yes 14 | 25,Female,99.0,Strong,Kolkata,No 15 | 64,Male,102.0,Mild,Bangalore,Yes 16 | 51,Male,104.0,Mild,Bangalore,No 17 | 70,Male,103.0,Strong,Kolkata,Yes 18 | 69,Female,103.0,Mild,Kolkata,Yes 19 | 40,Female,98.0,Strong,Delhi,No 20 | 64,Female,98.0,Mild,Bangalore,Yes 21 | 42,Female,,Strong,Bangalore,Yes 22 | 12,Male,98.0,Strong,Bangalore,No 23 | 73,Male,98.0,Mild,Bangalore,Yes 24 | 71,Female,98.0,Strong,Kolkata,Yes 25 | 80,Female,98.0,Mild,Delhi,Yes 26 | 13,Female,100.0,Strong,Kolkata,No 27 | 23,Male,,Mild,Mumbai,No 28 | 19,Female,100.0,Mild,Kolkata,Yes 29 | 33,Female,102.0,Strong,Delhi,No 30 | 16,Male,104.0,Mild,Kolkata,No 31 | 34,Female,,Strong,Mumbai,Yes 32 | 15,Male,101.0,Mild,Delhi,Yes 33 | 83,Male,103.0,Mild,Kolkata,No 34 | 34,Female,101.0,Strong,Delhi,Yes 35 | 26,Female,98.0,Mild,Kolkata,No 36 | 74,Male,102.0,Mild,Mumbai,Yes 37 | 82,Female,102.0,Strong,Bangalore,No 38 | 38,Female,101.0,Mild,Bangalore,No 39 | 55,Male,100.0,Mild,Kolkata,No 40 | 49,Female,101.0,Mild,Delhi,Yes 41 | 50,Female,103.0,Mild,Kolkata,No 42 | 49,Female,102.0,Mild,Delhi,No 43 | 82,Male,,Mild,Kolkata,Yes 44 | 27,Male,100.0,Mild,Delhi,Yes 45 | 22,Female,99.0,Mild,Bangalore,Yes 46 | 20,Male,102.0,Strong,Delhi,No 47 | 72,Male,99.0,Mild,Bangalore,No 48 | 19,Female,101.0,Mild,Mumbai,No 49 | 18,Female,104.0,Mild,Bangalore,No 50 | 66,Male,99.0,Strong,Bangalore,No 51 | 44,Male,104.0,Mild,Mumbai,No 52 | 19,Male,101.0,Mild,Delhi,Yes 53 | 11,Female,100.0,Strong,Kolkata,Yes 54 | 47,Female,100.0,Strong,Bangalore,Yes 55 | 83,Male,98.0,Mild,Delhi,Yes 56 | 60,Female,99.0,Mild,Mumbai,Yes 57 | 81,Female,101.0,Mild,Mumbai,Yes 58 | 71,Male,,Strong,Kolkata,No 59 | 49,Female,99.0,Strong,Bangalore,No 60 | 23,Male,98.0,Strong,Mumbai,Yes 61 | 6,Female,104.0,Mild,Kolkata,Yes 62 | 24,Female,102.0,Strong,Bangalore,Yes 63 | 81,Female,98.0,Strong,Mumbai,No 64 | 56,Female,104.0,Strong,Bangalore,Yes 65 | 10,Male,100.0,Mild,Bangalore,No 66 | 42,Male,104.0,Mild,Mumbai,No 67 | 69,Female,102.0,Mild,Bangalore,No 68 | 51,Male,104.0,Mild,Kolkata,No 69 | 65,Male,99.0,Mild,Bangalore,No 70 | 54,Female,104.0,Strong,Kolkata,No 71 | 73,Female,103.0,Mild,Delhi,No 72 | 68,Female,101.0,Strong,Delhi,No 73 | 75,Female,104.0,Strong,Delhi,No 74 | 83,Female,101.0,Mild,Kolkata,No 75 | 34,Male,98.0,Strong,Kolkata,Yes 76 | 34,Female,104.0,Strong,Delhi,No 77 | 5,Male,102.0,Mild,Kolkata,Yes 78 | 80,Male,100.0,Mild,Bangalore,Yes 79 | 8,Female,101.0,Mild,Kolkata,No 80 | 11,Male,100.0,Mild,Bangalore,Yes 81 | 48,Female,103.0,Mild,Kolkata,Yes 82 | 14,Female,99.0,Mild,Mumbai,Yes 83 | 65,Male,99.0,Mild,Delhi,No 84 | 24,Male,98.0,Mild,Kolkata,Yes 85 | 17,Female,104.0,Mild,Kolkata,No 86 | 69,Female,98.0,Strong,Mumbai,No 87 | 16,Female,103.0,Mild,Bangalore,Yes 88 | 25,Male,104.0,Mild,Bangalore,Yes 89 | 47,Male,101.0,Strong,Bangalore,No 90 | 5,Female,100.0,Mild,Kolkata,No 91 | 46,Male,103.0,Strong,Bangalore,No 92 | 59,Female,99.0,Strong,Delhi,No 93 | 38,Male,,Mild,Delhi,Yes 94 | 82,Female,102.0,Strong,Kolkata,No 95 | 27,Male,100.0,Mild,Kolkata,Yes 96 | 79,Male,,Strong,Kolkata,Yes 97 | 12,Female,104.0,Mild,Bangalore,No 98 | 51,Female,101.0,Strong,Kolkata,Yes 99 | 20,Female,101.0,Mild,Bangalore,No 100 | 5,Female,98.0,Strong,Mumbai,No 101 | 10,Female,98.0,Strong,Kolkata,Yes 102 | -------------------------------------------------------------------------------- /day57-elasticnet-regression/elastic-net-regression.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 70, 6 | "id": "71e28874", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "from sklearn.datasets import load_diabetes\n", 11 | "from sklearn.linear_model import LinearRegression,Ridge,Lasso,ElasticNet\n", 12 | "from sklearn.model_selection import train_test_split\n", 13 | "from sklearn.metrics import r2_score" 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": 71, 19 | "id": "284ccf3c", 20 | "metadata": {}, 21 | "outputs": [], 22 | "source": [ 23 | "X,y = load_diabetes(return_X_y=True)" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": 72, 29 | "id": "799d9080", 30 | "metadata": {}, 31 | "outputs": [], 32 | "source": [ 33 | "X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=2)" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": 73, 39 | "id": "8a242b9f", 40 | "metadata": {}, 41 | "outputs": [ 42 | { 43 | "data": { 44 | "text/plain": [ 45 | "0.4399387660024645" 46 | ] 47 | }, 48 | "execution_count": 73, 49 | "metadata": {}, 50 | "output_type": "execute_result" 51 | } 52 | ], 53 | "source": [ 54 | "# Linear Regression\n", 55 | "reg = LinearRegression()\n", 56 | "reg.fit(X_train,y_train)\n", 57 | "y_pred = reg.predict(X_test)\n", 58 | "r2_score(y_test,y_pred)" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": 74, 64 | "id": "a41eb10c", 65 | "metadata": {}, 66 | "outputs": [ 67 | { 68 | "data": { 69 | "text/plain": [ 70 | "0.4519973816947852" 71 | ] 72 | }, 73 | "execution_count": 74, 74 | "metadata": {}, 75 | "output_type": "execute_result" 76 | } 77 | ], 78 | "source": [ 79 | "# Ridge \n", 80 | "reg = Ridge(alpha=0.1)\n", 81 | "reg.fit(X_train,y_train)\n", 82 | "y_pred = reg.predict(X_test)\n", 83 | "r2_score(y_test,y_pred)" 84 | ] 85 | }, 86 | { 87 | "cell_type": "code", 88 | "execution_count": 75, 89 | "id": "b6b53e7c", 90 | "metadata": {}, 91 | "outputs": [ 92 | { 93 | "data": { 94 | "text/plain": [ 95 | "0.4411227990495632" 96 | ] 97 | }, 98 | "execution_count": 75, 99 | "metadata": {}, 100 | "output_type": "execute_result" 101 | } 102 | ], 103 | "source": [ 104 | "# Lasso\n", 105 | "reg = Lasso(alpha=0.01)\n", 106 | "reg.fit(X_train,y_train)\n", 107 | "y_pred = reg.predict(X_test)\n", 108 | "r2_score(y_test,y_pred)" 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": 76, 114 | "id": "5fc65b12", 115 | "metadata": {}, 116 | "outputs": [ 117 | { 118 | "data": { 119 | "text/plain": [ 120 | "0.4531493801165679" 121 | ] 122 | }, 123 | "execution_count": 76, 124 | "metadata": {}, 125 | "output_type": "execute_result" 126 | } 127 | ], 128 | "source": [ 129 | "# ElasticNet\n", 130 | "reg = ElasticNet(alpha=0.005,l1_ratio=0.9)\n", 131 | "reg.fit(X_train,y_train)\n", 132 | "y_pred = reg.predict(X_test)\n", 133 | "r2_score(y_test,y_pred)" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": null, 139 | "id": "0cb67b0c", 140 | "metadata": {}, 141 | "outputs": [], 142 | "source": [] 143 | } 144 | ], 145 | "metadata": { 146 | "kernelspec": { 147 | "display_name": "Python 3", 148 | "language": "python", 149 | "name": "python3" 150 | }, 151 | "language_info": { 152 | "codemirror_mode": { 153 | "name": "ipython", 154 | "version": 3 155 | }, 156 | "file_extension": ".py", 157 | "mimetype": "text/x-python", 158 | "name": "python", 159 | "nbconvert_exporter": "python", 160 | "pygments_lexer": "ipython3", 161 | "version": "3.8.8" 162 | } 163 | }, 164 | "nbformat": 4, 165 | "nbformat_minor": 5 166 | } 167 | -------------------------------------------------------------------------------- /day29-sklearn-pipelines/predict-without-pipeline.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 19, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "import pickle\n", 10 | "import numpy as np" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 20, 16 | "metadata": {}, 17 | "outputs": [], 18 | "source": [ 19 | "ohe_sex = pickle.load(open('models/ohe_sex.pkl','rb'))\n", 20 | "ohe_embarked = pickle.load(open('models/ohe_embarked.pkl','rb'))\n", 21 | "clf = pickle.load(open('models/clf.pkl','rb'))" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 21, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "# Assume user input\n", 31 | "# Pclass/gender/age/SibSp/Parch/Fare/Embarked\n", 32 | "test_input = np.array([2, 'male', 31.0, 0, 0, 10.5, 'S'],dtype=object).reshape(1,7)" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 22, 38 | "metadata": {}, 39 | "outputs": [ 40 | { 41 | "data": { 42 | "text/plain": [ 43 | "array([[2, 'male', 31.0, 0, 0, 10.5, 'S']], dtype=object)" 44 | ] 45 | }, 46 | "execution_count": 22, 47 | "metadata": {}, 48 | "output_type": "execute_result" 49 | } 50 | ], 51 | "source": [ 52 | "test_input" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 23, 58 | "metadata": {}, 59 | "outputs": [], 60 | "source": [ 61 | "test_input_sex = ohe_sex.transform(test_input[:,1].reshape(1,1))" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": 24, 67 | "metadata": {}, 68 | "outputs": [ 69 | { 70 | "data": { 71 | "text/plain": [ 72 | "array([[0., 1.]])" 73 | ] 74 | }, 75 | "execution_count": 24, 76 | "metadata": {}, 77 | "output_type": "execute_result" 78 | } 79 | ], 80 | "source": [ 81 | "test_input_sex" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 25, 87 | "metadata": {}, 88 | "outputs": [], 89 | "source": [ 90 | "test_input_embarked = ohe_embarked.transform(test_input[:,-1].reshape(1,1))" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 26, 96 | "metadata": {}, 97 | "outputs": [ 98 | { 99 | "data": { 100 | "text/plain": [ 101 | "array([[0., 0., 1.]])" 102 | ] 103 | }, 104 | "execution_count": 26, 105 | "metadata": {}, 106 | "output_type": "execute_result" 107 | } 108 | ], 109 | "source": [ 110 | "test_input_embarked" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": 14, 116 | "metadata": {}, 117 | "outputs": [], 118 | "source": [ 119 | "test_input_age = test_input[:,2].reshape(1,1)" 120 | ] 121 | }, 122 | { 123 | "cell_type": "code", 124 | "execution_count": 27, 125 | "metadata": {}, 126 | "outputs": [], 127 | "source": [ 128 | "test_input_transformed = np.concatenate((test_input[:,[0,3,4,5]],test_input_age,test_input_sex,test_input_embarked),axis=1)" 129 | ] 130 | }, 131 | { 132 | "cell_type": "code", 133 | "execution_count": 28, 134 | "metadata": {}, 135 | "outputs": [ 136 | { 137 | "data": { 138 | "text/plain": [ 139 | "(1, 10)" 140 | ] 141 | }, 142 | "execution_count": 28, 143 | "metadata": {}, 144 | "output_type": "execute_result" 145 | } 146 | ], 147 | "source": [ 148 | "test_input_transformed.shape" 149 | ] 150 | }, 151 | { 152 | "cell_type": "code", 153 | "execution_count": 29, 154 | "metadata": {}, 155 | "outputs": [ 156 | { 157 | "data": { 158 | "text/plain": [ 159 | "array([1], dtype=int64)" 160 | ] 161 | }, 162 | "execution_count": 29, 163 | "metadata": {}, 164 | "output_type": "execute_result" 165 | } 166 | ], 167 | "source": [ 168 | "clf.predict(test_input_transformed)" 169 | ] 170 | }, 171 | { 172 | "cell_type": "code", 173 | "execution_count": null, 174 | "metadata": {}, 175 | "outputs": [], 176 | "source": [] 177 | } 178 | ], 179 | "metadata": { 180 | "kernelspec": { 181 | "display_name": "Python 3", 182 | "language": "python", 183 | "name": "python3" 184 | }, 185 | "language_info": { 186 | "codemirror_mode": { 187 | "name": "ipython", 188 | "version": 3 189 | }, 190 | "file_extension": ".py", 191 | "mimetype": "text/x-python", 192 | "name": "python", 193 | "nbconvert_exporter": "python", 194 | "pygments_lexer": "ipython3", 195 | "version": "3.8.3" 196 | } 197 | }, 198 | "nbformat": 4, 199 | "nbformat_minor": 4 200 | } 201 | -------------------------------------------------------------------------------- /day55-regularized-linear-models/ridge-regression-from-scratch.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 118, 6 | "id": "99dcba6d", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "from sklearn.datasets import load_diabetes\n", 11 | "from sklearn.metrics import r2_score\n", 12 | "import numpy as np" 13 | ] 14 | }, 15 | { 16 | "cell_type": "code", 17 | "execution_count": 119, 18 | "id": "821f3faf", 19 | "metadata": {}, 20 | "outputs": [], 21 | "source": [ 22 | "X,y = load_diabetes(return_X_y=True)" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": 120, 28 | "id": "741b4551", 29 | "metadata": {}, 30 | "outputs": [], 31 | "source": [ 32 | "from sklearn.model_selection import train_test_split" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 121, 38 | "id": "5d4d2d1b", 39 | "metadata": {}, 40 | "outputs": [], 41 | "source": [ 42 | "X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=4)" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 122, 48 | "id": "30a774ef", 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "from sklearn.linear_model import Ridge" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 123, 58 | "id": "5a15c5fe", 59 | "metadata": {}, 60 | "outputs": [], 61 | "source": [ 62 | "reg = Ridge(alpha=0.1,solver='cholesky')" 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": 124, 68 | "id": "7d66d9f4", 69 | "metadata": {}, 70 | "outputs": [ 71 | { 72 | "data": { 73 | "text/plain": [ 74 | "Ridge(alpha=0.1, solver='cholesky')" 75 | ] 76 | }, 77 | "execution_count": 124, 78 | "metadata": {}, 79 | "output_type": "execute_result" 80 | } 81 | ], 82 | "source": [ 83 | "reg.fit(X_train,y_train)" 84 | ] 85 | }, 86 | { 87 | "cell_type": "code", 88 | "execution_count": 125, 89 | "id": "09460a79", 90 | "metadata": {}, 91 | "outputs": [ 92 | { 93 | "data": { 94 | "text/plain": [ 95 | "0.46930668289209754" 96 | ] 97 | }, 98 | "execution_count": 125, 99 | "metadata": {}, 100 | "output_type": "execute_result" 101 | } 102 | ], 103 | "source": [ 104 | "y_pred = reg.predict(X_test)\n", 105 | "r2_score(y_test,y_pred)" 106 | ] 107 | }, 108 | { 109 | "cell_type": "code", 110 | "execution_count": 126, 111 | "id": "927958f9", 112 | "metadata": {}, 113 | "outputs": [ 114 | { 115 | "name": "stdout", 116 | "output_type": "stream", 117 | "text": [ 118 | "[ 44.02025512 -241.69666596 452.98163524 332.04993719 -76.34010147\n", 119 | " -68.52063199 -164.98817213 149.9687712 431.61985919 58.51762582]\n", 120 | "150.89050209333024\n" 121 | ] 122 | } 123 | ], 124 | "source": [ 125 | "print(reg.coef_)\n", 126 | "print(reg.intercept_)" 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": 131, 132 | "id": "7ac16788", 133 | "metadata": {}, 134 | "outputs": [], 135 | "source": [ 136 | "class MeraRidge:\n", 137 | " \n", 138 | " def __init__(self,alpha=0.1):\n", 139 | " \n", 140 | " self.alpha = alpha\n", 141 | " self.coef_ = None\n", 142 | " self.intercept_ = None\n", 143 | " \n", 144 | " def fit(self,X_train,y_train):\n", 145 | " \n", 146 | " X_train = np.insert(X_train,0,1,axis=1)\n", 147 | " I = np.identity(X_train.shape[1])\n", 148 | " I[0][0] = 0\n", 149 | " result = np.linalg.inv(np.dot(X_train.T,X_train) + self.alpha * I).dot(X_train.T).dot(y_train)\n", 150 | " self.intercept_ = result[0]\n", 151 | " self.coef_ = result[1:]\n", 152 | " \n", 153 | " def predict(self,X_test):\n", 154 | " return np.dot(X_test,self.coef_) + self.intercept_" 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": 132, 160 | "id": "0884ea38", 161 | "metadata": {}, 162 | "outputs": [ 163 | { 164 | "name": "stdout", 165 | "output_type": "stream", 166 | "text": [ 167 | "0.46930668289209776\n", 168 | "[ 44.02025512 -241.69666596 452.98163524 332.04993719 -76.34010147\n", 169 | " -68.52063199 -164.98817213 149.9687712 431.61985919 58.51762582]\n", 170 | "150.8905020933302\n" 171 | ] 172 | } 173 | ], 174 | "source": [ 175 | "reg = MeraRidge()\n", 176 | "reg.fit(X_train,y_train)\n", 177 | "y_pred = reg.predict(X_test)\n", 178 | "print(r2_score(y_test,y_pred))\n", 179 | "print(reg.coef_)\n", 180 | "print(reg.intercept_)" 181 | ] 182 | }, 183 | { 184 | "cell_type": "code", 185 | "execution_count": null, 186 | "id": "807e38bc", 187 | "metadata": {}, 188 | "outputs": [], 189 | "source": [] 190 | } 191 | ], 192 | "metadata": { 193 | "kernelspec": { 194 | "display_name": "Python 3", 195 | "language": "python", 196 | "name": "python3" 197 | }, 198 | "language_info": { 199 | "codemirror_mode": { 200 | "name": "ipython", 201 | "version": 3 202 | }, 203 | "file_extension": ".py", 204 | "mimetype": "text/x-python", 205 | "name": "python", 206 | "nbconvert_exporter": "python", 207 | "pygments_lexer": "ipython3", 208 | "version": "3.8.8" 209 | } 210 | }, 211 | "nbformat": 4, 212 | "nbformat_minor": 5 213 | } 214 | -------------------------------------------------------------------------------- /day55-regularized-linear-models/ridge-regression-gradient-descent.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 99, 6 | "id": "0a64ff79", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "from sklearn.datasets import load_diabetes\n", 11 | "from sklearn.metrics import r2_score\n", 12 | "import numpy as np" 13 | ] 14 | }, 15 | { 16 | "cell_type": "code", 17 | "execution_count": 100, 18 | "id": "f5d0adc9", 19 | "metadata": {}, 20 | "outputs": [], 21 | "source": [ 22 | "X,y = load_diabetes(return_X_y=True)" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": 101, 28 | "id": "877a6fcc", 29 | "metadata": {}, 30 | "outputs": [], 31 | "source": [ 32 | "from sklearn.model_selection import train_test_split" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 102, 38 | "id": "f356594b", 39 | "metadata": {}, 40 | "outputs": [], 41 | "source": [ 42 | "X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=4)" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 103, 48 | "id": "7353416f", 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "from sklearn.linear_model import SGDRegressor" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 104, 58 | "id": "dd9147db", 59 | "metadata": {}, 60 | "outputs": [], 61 | "source": [ 62 | "reg = SGDRegressor(penalty='l2',max_iter=500,eta0=0.1,learning_rate='constant',alpha=0.001)" 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": 105, 68 | "id": "bc87d135", 69 | "metadata": {}, 70 | "outputs": [ 71 | { 72 | "name": "stdout", 73 | "output_type": "stream", 74 | "text": [ 75 | "R2 score 0.4408783662250152\n", 76 | "[ 49.38829154 -148.993237 366.84437837 266.5147463 -3.39784865\n", 77 | " -55.23108181 -167.55525594 138.12877883 325.67055866 101.75650011]\n", 78 | "[145.99981928]\n" 79 | ] 80 | } 81 | ], 82 | "source": [ 83 | "reg.fit(X_train,y_train)\n", 84 | "\n", 85 | "y_pred = reg.predict(X_test)\n", 86 | "print(\"R2 score\",r2_score(y_test,y_pred))\n", 87 | "print(reg.coef_)\n", 88 | "print(reg.intercept_)" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": 106, 94 | "id": "d9b329c6", 95 | "metadata": {}, 96 | "outputs": [], 97 | "source": [ 98 | "from sklearn.linear_model import Ridge\n", 99 | "\n", 100 | "reg = Ridge(alpha=0.001, max_iter=500,solver='sparse_cg')" 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": 107, 106 | "id": "67492f20", 107 | "metadata": {}, 108 | "outputs": [ 109 | { 110 | "name": "stdout", 111 | "output_type": "stream", 112 | "text": [ 113 | "R2 score 0.46238922017853457\n", 114 | "[ 34.62617431 -290.42643559 483.96594581 367.96559729 -852.21640464\n", 115 | " 498.74459944 183.78210203 276.57704126 757.34559544 36.95860457]\n", 116 | "151.1041692189411\n" 117 | ] 118 | } 119 | ], 120 | "source": [ 121 | "reg.fit(X_train,y_train)\n", 122 | "\n", 123 | "y_pred = reg.predict(X_test)\n", 124 | "print(\"R2 score\",r2_score(y_test,y_pred))\n", 125 | "print(reg.coef_)\n", 126 | "print(reg.intercept_)" 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": 108, 132 | "id": "9c215108", 133 | "metadata": {}, 134 | "outputs": [], 135 | "source": [ 136 | "class MeraRidgeGD:\n", 137 | " \n", 138 | " def __init__(self,epochs,learning_rate,alpha):\n", 139 | " \n", 140 | " self.learning_rate = learning_rate\n", 141 | " self.epochs = epochs\n", 142 | " self.alpha = alpha\n", 143 | " self.coef_ = None\n", 144 | " self.intercept_ = None\n", 145 | " \n", 146 | " def fit(self,X_train,y_train):\n", 147 | " \n", 148 | " self.coef_ = np.ones(X_train.shape[1])\n", 149 | " self.intercept_ = 0\n", 150 | " thetha = np.insert(self.coef_,0,self.intercept_)\n", 151 | " \n", 152 | " X_train = np.insert(X_train,0,1,axis=1)\n", 153 | " \n", 154 | " for i in range(self.epochs):\n", 155 | " thetha_der = np.dot(X_train.T,X_train).dot(thetha) - np.dot(X_train.T,y_train) + self.alpha*thetha\n", 156 | " thetha = thetha - self.learning_rate*thetha_der\n", 157 | " \n", 158 | " self.coef_ = thetha[1:]\n", 159 | " self.intercept_ = thetha[0]\n", 160 | " \n", 161 | " def predict(self,X_test):\n", 162 | " \n", 163 | " return np.dot(X_test,self.coef_) + self.intercept_" 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": 109, 169 | "id": "12040494", 170 | "metadata": {}, 171 | "outputs": [], 172 | "source": [ 173 | "reg = MeraRidgeGD(epochs=500,alpha=0.001,learning_rate=0.005)" 174 | ] 175 | }, 176 | { 177 | "cell_type": "code", 178 | "execution_count": 110, 179 | "id": "cd5d4820", 180 | "metadata": {}, 181 | "outputs": [ 182 | { 183 | "name": "stdout", 184 | "output_type": "stream", 185 | "text": [ 186 | "R2 score 0.47379622696725354\n", 187 | "[ 46.65040212 -221.37723801 452.11770407 325.54645024 -29.09573382\n", 188 | " -96.47613436 -190.90029664 146.3286965 400.80754967 95.08979987]\n", 189 | "150.86972442733904\n" 190 | ] 191 | } 192 | ], 193 | "source": [ 194 | "reg.fit(X_train,y_train)\n", 195 | "\n", 196 | "y_pred = reg.predict(X_test)\n", 197 | "print(\"R2 score\",r2_score(y_test,y_pred))\n", 198 | "print(reg.coef_)\n", 199 | "print(reg.intercept_)" 200 | ] 201 | }, 202 | { 203 | "cell_type": "code", 204 | "execution_count": null, 205 | "id": "629a5361", 206 | "metadata": {}, 207 | "outputs": [], 208 | "source": [] 209 | } 210 | ], 211 | "metadata": { 212 | "kernelspec": { 213 | "display_name": "Python 3", 214 | "language": "python", 215 | "name": "python3" 216 | }, 217 | "language_info": { 218 | "codemirror_mode": { 219 | "name": "ipython", 220 | "version": 3 221 | }, 222 | "file_extension": ".py", 223 | "mimetype": "text/x-python", 224 | "name": "python", 225 | "nbconvert_exporter": "python", 226 | "pygments_lexer": "ipython3", 227 | "version": "3.8.8" 228 | } 229 | }, 230 | "nbformat": 4, 231 | "nbformat_minor": 5 232 | } 233 | -------------------------------------------------------------------------------- /day52-types-of-gradient-descent/batch-gradient-descent.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 10, 6 | "id": "7d78b116", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "from sklearn.datasets import load_diabetes\n", 11 | "\n", 12 | "import numpy as np\n", 13 | "from sklearn.linear_model import LinearRegression\n", 14 | "from sklearn.metrics import r2_score\n", 15 | "from sklearn.model_selection import train_test_split" 16 | ] 17 | }, 18 | { 19 | "cell_type": "code", 20 | "execution_count": 11, 21 | "id": "6b46625d", 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [ 25 | "X,y = load_diabetes(return_X_y=True)" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 12, 31 | "id": "c2ad6cd1", 32 | "metadata": {}, 33 | "outputs": [ 34 | { 35 | "name": "stdout", 36 | "output_type": "stream", 37 | "text": [ 38 | "(442, 10)\n", 39 | "(442,)\n" 40 | ] 41 | } 42 | ], 43 | "source": [ 44 | "print(X.shape)\n", 45 | "print(y.shape)" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": 13, 51 | "id": "a70d2eb2", 52 | "metadata": {}, 53 | "outputs": [], 54 | "source": [ 55 | "X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=2)" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": 14, 61 | "id": "a8ec5613", 62 | "metadata": {}, 63 | "outputs": [ 64 | { 65 | "data": { 66 | "text/plain": [ 67 | "LinearRegression()" 68 | ] 69 | }, 70 | "execution_count": 14, 71 | "metadata": {}, 72 | "output_type": "execute_result" 73 | } 74 | ], 75 | "source": [ 76 | "reg = LinearRegression()\n", 77 | "reg.fit(X_train,y_train)" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 15, 83 | "id": "d3e3934e", 84 | "metadata": {}, 85 | "outputs": [ 86 | { 87 | "name": "stdout", 88 | "output_type": "stream", 89 | "text": [ 90 | "[ -9.16088483 -205.46225988 516.68462383 340.62734108 -895.54360867\n", 91 | " 561.21453306 153.88478595 126.73431596 861.12139955 52.41982836]\n", 92 | "151.88334520854633\n" 93 | ] 94 | } 95 | ], 96 | "source": [ 97 | "print(reg.coef_)\n", 98 | "print(reg.intercept_)" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": 16, 104 | "id": "d8b0bb30", 105 | "metadata": {}, 106 | "outputs": [ 107 | { 108 | "data": { 109 | "text/plain": [ 110 | "0.4399387660024645" 111 | ] 112 | }, 113 | "execution_count": 16, 114 | "metadata": {}, 115 | "output_type": "execute_result" 116 | } 117 | ], 118 | "source": [ 119 | "y_pred = reg.predict(X_test)\n", 120 | "r2_score(y_test,y_pred)" 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": 17, 126 | "id": "b5f8dc27", 127 | "metadata": {}, 128 | "outputs": [ 129 | { 130 | "data": { 131 | "text/plain": [ 132 | "(353, 10)" 133 | ] 134 | }, 135 | "execution_count": 17, 136 | "metadata": {}, 137 | "output_type": "execute_result" 138 | } 139 | ], 140 | "source": [ 141 | "X_train.shape" 142 | ] 143 | }, 144 | { 145 | "cell_type": "code", 146 | "execution_count": 96, 147 | "id": "777721d5", 148 | "metadata": {}, 149 | "outputs": [], 150 | "source": [ 151 | "class GDRegressor:\n", 152 | " \n", 153 | " def __init__(self,learning_rate=0.01,epochs=100):\n", 154 | " \n", 155 | " self.coef_ = None\n", 156 | " self.intercept_ = None\n", 157 | " self.lr = learning_rate\n", 158 | " self.epochs = epochs\n", 159 | " \n", 160 | " def fit(self,X_train,y_train):\n", 161 | " # init your coefs\n", 162 | " self.intercept_ = 0\n", 163 | " self.coef_ = np.ones(X_train.shape[1])\n", 164 | " \n", 165 | " for i in range(self.epochs):\n", 166 | " # update all the coef and the intercept\n", 167 | " y_hat = np.dot(X_train,self.coef_) + self.intercept_\n", 168 | " #print(\"Shape of y_hat\",y_hat.shape)\n", 169 | " intercept_der = -2 * np.mean(y_train - y_hat)\n", 170 | " self.intercept_ = self.intercept_ - (self.lr * intercept_der)\n", 171 | " \n", 172 | " coef_der = -2 * np.dot((y_train - y_hat),X_train)/X_train.shape[0]\n", 173 | " self.coef_ = self.coef_ - (self.lr * coef_der)\n", 174 | " \n", 175 | " print(self.intercept_,self.coef_)\n", 176 | " \n", 177 | " def predict(self,X_test):\n", 178 | " return np.dot(X_test,self.coef_) + self.intercept_" 179 | ] 180 | }, 181 | { 182 | "cell_type": "code", 183 | "execution_count": 109, 184 | "id": "4ecc1e6f", 185 | "metadata": {}, 186 | "outputs": [], 187 | "source": [ 188 | "gdr = GDRegressor(epochs=1000,learning_rate=0.5)" 189 | ] 190 | }, 191 | { 192 | "cell_type": "code", 193 | "execution_count": 110, 194 | "id": "e7e6aec9", 195 | "metadata": {}, 196 | "outputs": [ 197 | { 198 | "name": "stdout", 199 | "output_type": "stream", 200 | "text": [ 201 | "152.0135263267291 [ 14.38915082 -173.72674118 491.54504015 323.91983579 -39.32680194\n", 202 | " -116.01099114 -194.04229501 103.38216641 451.63385893 97.57119174]\n" 203 | ] 204 | } 205 | ], 206 | "source": [ 207 | "gdr.fit(X_train,y_train)" 208 | ] 209 | }, 210 | { 211 | "cell_type": "code", 212 | "execution_count": 111, 213 | "id": "8e5e4410", 214 | "metadata": {}, 215 | "outputs": [], 216 | "source": [ 217 | "y_pred = gdr.predict(X_test)" 218 | ] 219 | }, 220 | { 221 | "cell_type": "code", 222 | "execution_count": 112, 223 | "id": "84f66db7", 224 | "metadata": {}, 225 | "outputs": [ 226 | { 227 | "data": { 228 | "text/plain": [ 229 | "0.4534524671450598" 230 | ] 231 | }, 232 | "execution_count": 112, 233 | "metadata": {}, 234 | "output_type": "execute_result" 235 | } 236 | ], 237 | "source": [ 238 | "r2_score(y_test,y_pred)" 239 | ] 240 | }, 241 | { 242 | "cell_type": "code", 243 | "execution_count": null, 244 | "id": "c8df72af", 245 | "metadata": {}, 246 | "outputs": [], 247 | "source": [] 248 | } 249 | ], 250 | "metadata": { 251 | "kernelspec": { 252 | "display_name": "Python 3", 253 | "language": "python", 254 | "name": "python3" 255 | }, 256 | "language_info": { 257 | "codemirror_mode": { 258 | "name": "ipython", 259 | "version": 3 260 | }, 261 | "file_extension": ".py", 262 | "mimetype": "text/x-python", 263 | "name": "python", 264 | "nbconvert_exporter": "python", 265 | "pygments_lexer": "ipython3", 266 | "version": "3.8.8" 267 | } 268 | }, 269 | "nbformat": 4, 270 | "nbformat_minor": 5 271 | } 272 | -------------------------------------------------------------------------------- /day65-random-forest/oob-score-demo.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 10, 6 | "id": "efabe5b1", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "import numpy as np\n", 11 | "import pandas as pd\n", 12 | "\n", 13 | "from sklearn.model_selection import train_test_split\n", 14 | "from sklearn.ensemble import RandomForestClassifier\n", 15 | "\n", 16 | "from sklearn.metrics import accuracy_score" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": 11, 22 | "id": "5e2a4c14", 23 | "metadata": {}, 24 | "outputs": [ 25 | { 26 | "data": { 27 | "text/html": [ 28 | "
\n", 29 | "\n", 42 | "\n", 43 | " \n", 44 | " \n", 45 | " \n", 46 | " \n", 47 | " \n", 48 | " \n", 49 | " \n", 50 | " \n", 51 | " \n", 52 | " \n", 53 | " \n", 54 | " \n", 55 | " \n", 56 | " \n", 57 | " \n", 58 | " \n", 59 | " \n", 60 | " \n", 61 | " \n", 62 | " \n", 63 | " \n", 64 | " \n", 65 | " \n", 66 | " \n", 67 | " \n", 68 | " \n", 69 | " \n", 70 | " \n", 71 | " \n", 72 | " \n", 73 | " \n", 74 | " \n", 75 | " \n", 76 | " \n", 77 | " \n", 78 | " \n", 79 | " \n", 80 | " \n", 81 | " \n", 82 | " \n", 83 | " \n", 84 | " \n", 85 | " \n", 86 | " \n", 87 | " \n", 88 | " \n", 89 | " \n", 90 | " \n", 91 | " \n", 92 | " \n", 93 | " \n", 94 | " \n", 95 | " \n", 96 | " \n", 97 | " \n", 98 | " \n", 99 | " \n", 100 | " \n", 101 | " \n", 102 | " \n", 103 | " \n", 104 | " \n", 105 | " \n", 106 | " \n", 107 | " \n", 108 | " \n", 109 | " \n", 110 | " \n", 111 | " \n", 112 | " \n", 113 | " \n", 114 | " \n", 115 | " \n", 116 | " \n", 117 | " \n", 118 | " \n", 119 | " \n", 120 | " \n", 121 | " \n", 122 | " \n", 123 | " \n", 124 | " \n", 125 | " \n", 126 | " \n", 127 | " \n", 128 | " \n", 129 | " \n", 130 | " \n", 131 | " \n", 132 | " \n", 133 | " \n", 134 | " \n", 135 | " \n", 136 | " \n", 137 | " \n", 138 | " \n", 139 | " \n", 140 | " \n", 141 | " \n", 142 | " \n", 143 | " \n", 144 | " \n", 145 | " \n", 146 | " \n", 147 | " \n", 148 | " \n", 149 | "
agesexcptrestbpscholfbsrestecgthalachexangoldpeakslopecathaltarget
063131452331015002.30011
137121302500118703.50021
241011302040017201.42021
356111202360117800.82021
457001203540116310.62021
\n", 150 | "
" 151 | ], 152 | "text/plain": [ 153 | " age sex cp trestbps chol fbs restecg thalach exang oldpeak slope \\\n", 154 | "0 63 1 3 145 233 1 0 150 0 2.3 0 \n", 155 | "1 37 1 2 130 250 0 1 187 0 3.5 0 \n", 156 | "2 41 0 1 130 204 0 0 172 0 1.4 2 \n", 157 | "3 56 1 1 120 236 0 1 178 0 0.8 2 \n", 158 | "4 57 0 0 120 354 0 1 163 1 0.6 2 \n", 159 | "\n", 160 | " ca thal target \n", 161 | "0 0 1 1 \n", 162 | "1 0 2 1 \n", 163 | "2 0 2 1 \n", 164 | "3 0 2 1 \n", 165 | "4 0 2 1 " 166 | ] 167 | }, 168 | "execution_count": 11, 169 | "metadata": {}, 170 | "output_type": "execute_result" 171 | } 172 | ], 173 | "source": [ 174 | "df = pd.read_csv('heart.csv')\n", 175 | "df.head()" 176 | ] 177 | }, 178 | { 179 | "cell_type": "code", 180 | "execution_count": 12, 181 | "id": "a0ea7498", 182 | "metadata": {}, 183 | "outputs": [], 184 | "source": [ 185 | "X = df.iloc[:,0:-1]\n", 186 | "y = df.iloc[:,-1]" 187 | ] 188 | }, 189 | { 190 | "cell_type": "code", 191 | "execution_count": 13, 192 | "id": "ec0525a0", 193 | "metadata": {}, 194 | "outputs": [], 195 | "source": [ 196 | "X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=42)" 197 | ] 198 | }, 199 | { 200 | "cell_type": "code", 201 | "execution_count": 14, 202 | "id": "fb303d14", 203 | "metadata": {}, 204 | "outputs": [], 205 | "source": [ 206 | "rf = RandomForestClassifier(oob_score=True)" 207 | ] 208 | }, 209 | { 210 | "cell_type": "code", 211 | "execution_count": 15, 212 | "id": "0147b670", 213 | "metadata": {}, 214 | "outputs": [ 215 | { 216 | "data": { 217 | "text/plain": [ 218 | "RandomForestClassifier(oob_score=True)" 219 | ] 220 | }, 221 | "execution_count": 15, 222 | "metadata": {}, 223 | "output_type": "execute_result" 224 | } 225 | ], 226 | "source": [ 227 | "rf.fit(X_train,y_train)" 228 | ] 229 | }, 230 | { 231 | "cell_type": "code", 232 | "execution_count": 16, 233 | "id": "01b1098b", 234 | "metadata": {}, 235 | "outputs": [ 236 | { 237 | "data": { 238 | "text/plain": [ 239 | "0.8057851239669421" 240 | ] 241 | }, 242 | "execution_count": 16, 243 | "metadata": {}, 244 | "output_type": "execute_result" 245 | } 246 | ], 247 | "source": [ 248 | "rf.oob_score_" 249 | ] 250 | }, 251 | { 252 | "cell_type": "code", 253 | "execution_count": 17, 254 | "id": "508b7fb8", 255 | "metadata": {}, 256 | "outputs": [ 257 | { 258 | "data": { 259 | "text/plain": [ 260 | "0.8688524590163934" 261 | ] 262 | }, 263 | "execution_count": 17, 264 | "metadata": {}, 265 | "output_type": "execute_result" 266 | } 267 | ], 268 | "source": [ 269 | "y_pred = rf.predict(X_test)\n", 270 | "accuracy_score(y_test,y_pred)" 271 | ] 272 | }, 273 | { 274 | "cell_type": "code", 275 | "execution_count": null, 276 | "id": "25b3f783", 277 | "metadata": {}, 278 | "outputs": [], 279 | "source": [] 280 | } 281 | ], 282 | "metadata": { 283 | "kernelspec": { 284 | "display_name": "Python 3", 285 | "language": "python", 286 | "name": "python3" 287 | }, 288 | "language_info": { 289 | "codemirror_mode": { 290 | "name": "ipython", 291 | "version": 3 292 | }, 293 | "file_extension": ".py", 294 | "mimetype": "text/x-python", 295 | "name": "python", 296 | "nbconvert_exporter": "python", 297 | "pygments_lexer": "ipython3", 298 | "version": "3.8.8" 299 | } 300 | }, 301 | "nbformat": 4, 302 | "nbformat_minor": 5 303 | } 304 | -------------------------------------------------------------------------------- /day52-types-of-gradient-descent/stochastic-gradient-descent-from-scratch.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 60, 6 | "id": "60e43fd7", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "from sklearn.datasets import load_diabetes\n", 11 | "\n", 12 | "import numpy as np\n", 13 | "from sklearn.linear_model import LinearRegression\n", 14 | "from sklearn.metrics import r2_score\n", 15 | "from sklearn.model_selection import train_test_split\n", 16 | "import time" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": 2, 22 | "id": "a90f5266", 23 | "metadata": {}, 24 | "outputs": [], 25 | "source": [ 26 | "X,y = load_diabetes(return_X_y=True)" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": 3, 32 | "id": "51ea6596", 33 | "metadata": {}, 34 | "outputs": [ 35 | { 36 | "name": "stdout", 37 | "output_type": "stream", 38 | "text": [ 39 | "(442, 10)\n", 40 | "(442,)\n" 41 | ] 42 | } 43 | ], 44 | "source": [ 45 | "print(X.shape)\n", 46 | "print(y.shape)" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 4, 52 | "id": "7077f503", 53 | "metadata": {}, 54 | "outputs": [], 55 | "source": [ 56 | "X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=2)" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 5, 62 | "id": "eb4d3f4e", 63 | "metadata": {}, 64 | "outputs": [ 65 | { 66 | "data": { 67 | "text/plain": [ 68 | "LinearRegression()" 69 | ] 70 | }, 71 | "execution_count": 5, 72 | "metadata": {}, 73 | "output_type": "execute_result" 74 | } 75 | ], 76 | "source": [ 77 | "reg = LinearRegression()\n", 78 | "reg.fit(X_train,y_train)" 79 | ] 80 | }, 81 | { 82 | "cell_type": "code", 83 | "execution_count": 6, 84 | "id": "8af3b5af", 85 | "metadata": {}, 86 | "outputs": [ 87 | { 88 | "name": "stdout", 89 | "output_type": "stream", 90 | "text": [ 91 | "[ -9.16088483 -205.46225988 516.68462383 340.62734108 -895.54360867\n", 92 | " 561.21453306 153.88478595 126.73431596 861.12139955 52.41982836]\n", 93 | "151.88334520854633\n" 94 | ] 95 | } 96 | ], 97 | "source": [ 98 | "print(reg.coef_)\n", 99 | "print(reg.intercept_)" 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": 7, 105 | "id": "33459e4e", 106 | "metadata": {}, 107 | "outputs": [ 108 | { 109 | "data": { 110 | "text/plain": [ 111 | "0.4399387660024645" 112 | ] 113 | }, 114 | "execution_count": 7, 115 | "metadata": {}, 116 | "output_type": "execute_result" 117 | } 118 | ], 119 | "source": [ 120 | "y_pred = reg.predict(X_test)\n", 121 | "r2_score(y_test,y_pred)" 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": 29, 127 | "id": "ed75f3c1", 128 | "metadata": {}, 129 | "outputs": [], 130 | "source": [ 131 | "class SGDRegressor:\n", 132 | " \n", 133 | " def __init__(self,learning_rate=0.01,epochs=100):\n", 134 | " \n", 135 | " self.coef_ = None\n", 136 | " self.intercept_ = None\n", 137 | " self.lr = learning_rate\n", 138 | " self.epochs = epochs\n", 139 | " \n", 140 | " def fit(self,X_train,y_train):\n", 141 | " # init your coefs\n", 142 | " self.intercept_ = 0\n", 143 | " self.coef_ = np.ones(X_train.shape[1])\n", 144 | " \n", 145 | " for i in range(self.epochs):\n", 146 | " for j in range(X_train.shape[0]):\n", 147 | " idx = np.random.randint(0,X_train.shape[0])\n", 148 | " \n", 149 | " y_hat = np.dot(X_train[idx],self.coef_) + self.intercept_\n", 150 | " \n", 151 | " intercept_der = -2 * (y_train[idx] - y_hat)\n", 152 | " self.intercept_ = self.intercept_ - (self.lr * intercept_der)\n", 153 | " \n", 154 | " coef_der = -2 * np.dot((y_train[idx] - y_hat),X_train[idx])\n", 155 | " self.coef_ = self.coef_ - (self.lr * coef_der)\n", 156 | " \n", 157 | " print(self.intercept_,self.coef_)\n", 158 | " \n", 159 | " def predict(self,X_test):\n", 160 | " return np.dot(X_test,self.coef_) + self.intercept_" 161 | ] 162 | }, 163 | { 164 | "cell_type": "code", 165 | "execution_count": 56, 166 | "id": "028e7219", 167 | "metadata": {}, 168 | "outputs": [], 169 | "source": [ 170 | "sgd = SGDRegressor(learning_rate=0.01,epochs=40)" 171 | ] 172 | }, 173 | { 174 | "cell_type": "code", 175 | "execution_count": 61, 176 | "id": "aafb36fa", 177 | "metadata": {}, 178 | "outputs": [ 179 | { 180 | "name": "stdout", 181 | "output_type": "stream", 182 | "text": [ 183 | "157.2641767094034 [ 58.34618831 -41.65635944 314.02875897 219.47021721 30.2641263\n", 184 | " -8.98591625 -165.98040412 132.42543708 294.42536821 122.71528461]\n", 185 | "The time taken is 0.17459607124328613\n" 186 | ] 187 | } 188 | ], 189 | "source": [ 190 | "start = time.time()\n", 191 | "sgd.fit(X_train,y_train)\n", 192 | "print(\"The time taken is\",time.time() - start)" 193 | ] 194 | }, 195 | { 196 | "cell_type": "code", 197 | "execution_count": 58, 198 | "id": "829e9938", 199 | "metadata": {}, 200 | "outputs": [], 201 | "source": [ 202 | "y_pred = sgd.predict(X_test)" 203 | ] 204 | }, 205 | { 206 | "cell_type": "code", 207 | "execution_count": 62, 208 | "id": "128832b0", 209 | "metadata": {}, 210 | "outputs": [ 211 | { 212 | "data": { 213 | "text/plain": [ 214 | "0.4205755931585481" 215 | ] 216 | }, 217 | "execution_count": 62, 218 | "metadata": {}, 219 | "output_type": "execute_result" 220 | } 221 | ], 222 | "source": [ 223 | "r2_score(y_test,y_pred)" 224 | ] 225 | }, 226 | { 227 | "cell_type": "code", 228 | "execution_count": 63, 229 | "id": "457600ac", 230 | "metadata": {}, 231 | "outputs": [], 232 | "source": [ 233 | "from sklearn.linear_model import SGDRegressor" 234 | ] 235 | }, 236 | { 237 | "cell_type": "code", 238 | "execution_count": 89, 239 | "id": "fdd03179", 240 | "metadata": {}, 241 | "outputs": [], 242 | "source": [ 243 | "reg = SGDRegressor(max_iter=100,learning_rate='constant',eta0=0.01)" 244 | ] 245 | }, 246 | { 247 | "cell_type": "code", 248 | "execution_count": 90, 249 | "id": "37fd9602", 250 | "metadata": {}, 251 | "outputs": [ 252 | { 253 | "name": "stderr", 254 | "output_type": "stream", 255 | "text": [ 256 | "C:\\Users\\91842\\anaconda3\\lib\\site-packages\\sklearn\\linear_model\\_stochastic_gradient.py:1220: ConvergenceWarning: Maximum number of iteration reached before convergence. Consider increasing max_iter to improve the fit.\n", 257 | " warnings.warn(\"Maximum number of iteration reached before \"\n" 258 | ] 259 | }, 260 | { 261 | "data": { 262 | "text/plain": [ 263 | "SGDRegressor(learning_rate='constant', max_iter=100)" 264 | ] 265 | }, 266 | "execution_count": 90, 267 | "metadata": {}, 268 | "output_type": "execute_result" 269 | } 270 | ], 271 | "source": [ 272 | "reg.fit(X_train,y_train)" 273 | ] 274 | }, 275 | { 276 | "cell_type": "code", 277 | "execution_count": 91, 278 | "id": "6e28beda", 279 | "metadata": {}, 280 | "outputs": [], 281 | "source": [ 282 | "y_pred = reg.predict(X_test)" 283 | ] 284 | }, 285 | { 286 | "cell_type": "code", 287 | "execution_count": 92, 288 | "id": "3d3d24d4", 289 | "metadata": {}, 290 | "outputs": [ 291 | { 292 | "data": { 293 | "text/plain": [ 294 | "0.43059547063734904" 295 | ] 296 | }, 297 | "execution_count": 92, 298 | "metadata": {}, 299 | "output_type": "execute_result" 300 | } 301 | ], 302 | "source": [ 303 | "r2_score(y_test,y_pred)" 304 | ] 305 | }, 306 | { 307 | "cell_type": "code", 308 | "execution_count": null, 309 | "id": "eea1ab2a", 310 | "metadata": {}, 311 | "outputs": [], 312 | "source": [] 313 | }, 314 | { 315 | "cell_type": "code", 316 | "execution_count": null, 317 | "id": "4284bb71", 318 | "metadata": {}, 319 | "outputs": [], 320 | "source": [] 321 | } 322 | ], 323 | "metadata": { 324 | "kernelspec": { 325 | "display_name": "Python 3", 326 | "language": "python", 327 | "name": "python3" 328 | }, 329 | "language_info": { 330 | "codemirror_mode": { 331 | "name": "ipython", 332 | "version": 3 333 | }, 334 | "file_extension": ".py", 335 | "mimetype": "text/x-python", 336 | "name": "python", 337 | "nbconvert_exporter": "python", 338 | "pygments_lexer": "ipython3", 339 | "version": "3.8.8" 340 | } 341 | }, 342 | "nbformat": 4, 343 | "nbformat_minor": 5 344 | } 345 | -------------------------------------------------------------------------------- /day39-knn-imputer/day39.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 32, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "import numpy as np\n", 10 | "import pandas as pd\n", 11 | "\n", 12 | "from sklearn.model_selection import train_test_split\n", 13 | "\n", 14 | "from sklearn.impute import KNNImputer,SimpleImputer\n", 15 | "from sklearn.linear_model import LogisticRegression\n", 16 | "\n", 17 | "from sklearn.metrics import accuracy_score" 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": 33, 23 | "metadata": {}, 24 | "outputs": [], 25 | "source": [ 26 | "df = pd.read_csv('train.csv')[['Age','Pclass','Fare','Survived']]" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": 34, 32 | "metadata": {}, 33 | "outputs": [ 34 | { 35 | "data": { 36 | "text/html": [ 37 | "
\n", 38 | "\n", 51 | "\n", 52 | " \n", 53 | " \n", 54 | " \n", 55 | " \n", 56 | " \n", 57 | " \n", 58 | " \n", 59 | " \n", 60 | " \n", 61 | " \n", 62 | " \n", 63 | " \n", 64 | " \n", 65 | " \n", 66 | " \n", 67 | " \n", 68 | " \n", 69 | " \n", 70 | " \n", 71 | " \n", 72 | " \n", 73 | " \n", 74 | " \n", 75 | " \n", 76 | " \n", 77 | " \n", 78 | " \n", 79 | " \n", 80 | " \n", 81 | " \n", 82 | " \n", 83 | " \n", 84 | " \n", 85 | " \n", 86 | " \n", 87 | " \n", 88 | " \n", 89 | " \n", 90 | " \n", 91 | " \n", 92 | " \n", 93 | " \n", 94 | " \n", 95 | " \n", 96 | " \n", 97 | " \n", 98 | "
AgePclassFareSurvived
022.037.25000
138.0171.28331
226.037.92501
335.0153.10001
435.038.05000
\n", 99 | "
" 100 | ], 101 | "text/plain": [ 102 | " Age Pclass Fare Survived\n", 103 | "0 22.0 3 7.2500 0\n", 104 | "1 38.0 1 71.2833 1\n", 105 | "2 26.0 3 7.9250 1\n", 106 | "3 35.0 1 53.1000 1\n", 107 | "4 35.0 3 8.0500 0" 108 | ] 109 | }, 110 | "execution_count": 34, 111 | "metadata": {}, 112 | "output_type": "execute_result" 113 | } 114 | ], 115 | "source": [ 116 | "df.head()" 117 | ] 118 | }, 119 | { 120 | "cell_type": "code", 121 | "execution_count": 35, 122 | "metadata": {}, 123 | "outputs": [ 124 | { 125 | "data": { 126 | "text/plain": [ 127 | "Age 19.86532\n", 128 | "Pclass 0.00000\n", 129 | "Fare 0.00000\n", 130 | "Survived 0.00000\n", 131 | "dtype: float64" 132 | ] 133 | }, 134 | "execution_count": 35, 135 | "metadata": {}, 136 | "output_type": "execute_result" 137 | } 138 | ], 139 | "source": [ 140 | "df.isnull().mean() * 100" 141 | ] 142 | }, 143 | { 144 | "cell_type": "code", 145 | "execution_count": 36, 146 | "metadata": {}, 147 | "outputs": [], 148 | "source": [ 149 | "X = df.drop(columns=['Survived'])\n", 150 | "y = df['Survived']" 151 | ] 152 | }, 153 | { 154 | "cell_type": "code", 155 | "execution_count": 37, 156 | "metadata": {}, 157 | "outputs": [], 158 | "source": [ 159 | "X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=2)" 160 | ] 161 | }, 162 | { 163 | "cell_type": "code", 164 | "execution_count": 38, 165 | "metadata": {}, 166 | "outputs": [ 167 | { 168 | "data": { 169 | "text/html": [ 170 | "
\n", 171 | "\n", 184 | "\n", 185 | " \n", 186 | " \n", 187 | " \n", 188 | " \n", 189 | " \n", 190 | " \n", 191 | " \n", 192 | " \n", 193 | " \n", 194 | " \n", 195 | " \n", 196 | " \n", 197 | " \n", 198 | " \n", 199 | " \n", 200 | " \n", 201 | " \n", 202 | " \n", 203 | " \n", 204 | " \n", 205 | " \n", 206 | " \n", 207 | " \n", 208 | " \n", 209 | " \n", 210 | " \n", 211 | " \n", 212 | " \n", 213 | " \n", 214 | " \n", 215 | " \n", 216 | " \n", 217 | " \n", 218 | " \n", 219 | " \n", 220 | " \n", 221 | " \n", 222 | " \n", 223 | " \n", 224 | " \n", 225 | "
AgePclassFare
3040.0127.7208
104.0316.7000
87347.039.0000
1829.0331.3875
87620.039.8458
\n", 226 | "
" 227 | ], 228 | "text/plain": [ 229 | " Age Pclass Fare\n", 230 | "30 40.0 1 27.7208\n", 231 | "10 4.0 3 16.7000\n", 232 | "873 47.0 3 9.0000\n", 233 | "182 9.0 3 31.3875\n", 234 | "876 20.0 3 9.8458" 235 | ] 236 | }, 237 | "execution_count": 38, 238 | "metadata": {}, 239 | "output_type": "execute_result" 240 | } 241 | ], 242 | "source": [ 243 | "X_train.head()" 244 | ] 245 | }, 246 | { 247 | "cell_type": "code", 248 | "execution_count": 53, 249 | "metadata": {}, 250 | "outputs": [], 251 | "source": [ 252 | "knn = KNNImputer(n_neighbors=3,weights='distance')\n", 253 | "\n", 254 | "X_train_trf = knn.fit_transform(X_train)\n", 255 | "X_test_trf = knn.transform(X_test)" 256 | ] 257 | }, 258 | { 259 | "cell_type": "code", 260 | "execution_count": 54, 261 | "metadata": {}, 262 | "outputs": [ 263 | { 264 | "data": { 265 | "text/plain": [ 266 | "0.7150837988826816" 267 | ] 268 | }, 269 | "execution_count": 54, 270 | "metadata": {}, 271 | "output_type": "execute_result" 272 | } 273 | ], 274 | "source": [ 275 | "lr = LogisticRegression()\n", 276 | "\n", 277 | "lr.fit(X_train_trf,y_train)\n", 278 | "\n", 279 | "y_pred = lr.predict(X_test_trf)\n", 280 | "\n", 281 | "accuracy_score(y_test,y_pred)" 282 | ] 283 | }, 284 | { 285 | "cell_type": "code", 286 | "execution_count": 55, 287 | "metadata": {}, 288 | "outputs": [], 289 | "source": [ 290 | "# Comparision with Simple Imputer --> mean\n", 291 | "\n", 292 | "si = SimpleImputer()\n", 293 | "\n", 294 | "X_train_trf2 = si.fit_transform(X_train)\n", 295 | "X_test_trf2 = si.transform(X_test)" 296 | ] 297 | }, 298 | { 299 | "cell_type": "code", 300 | "execution_count": 56, 301 | "metadata": {}, 302 | "outputs": [ 303 | { 304 | "data": { 305 | "text/plain": [ 306 | "0.6927374301675978" 307 | ] 308 | }, 309 | "execution_count": 56, 310 | "metadata": {}, 311 | "output_type": "execute_result" 312 | } 313 | ], 314 | "source": [ 315 | "lr = LogisticRegression()\n", 316 | "\n", 317 | "lr.fit(X_train_trf2,y_train)\n", 318 | "\n", 319 | "y_pred2 = lr.predict(X_test_trf2)\n", 320 | "\n", 321 | "accuracy_score(y_test,y_pred2)" 322 | ] 323 | }, 324 | { 325 | "cell_type": "code", 326 | "execution_count": null, 327 | "metadata": {}, 328 | "outputs": [], 329 | "source": [] 330 | } 331 | ], 332 | "metadata": { 333 | "kernelspec": { 334 | "display_name": "Python 3", 335 | "language": "python", 336 | "name": "python3" 337 | }, 338 | "language_info": { 339 | "codemirror_mode": { 340 | "name": "ipython", 341 | "version": 3 342 | }, 343 | "file_extension": ".py", 344 | "mimetype": "text/x-python", 345 | "name": "python", 346 | "nbconvert_exporter": "python", 347 | "pygments_lexer": "ipython3", 348 | "version": "3.8.3" 349 | } 350 | }, 351 | "nbformat": 4, 352 | "nbformat_minor": 4 353 | } 354 | -------------------------------------------------------------------------------- /day52-types-of-gradient-descent/mini-batch-gradient-descent-from-scratch.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 38, 6 | "id": "e1d1b3f6", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "from sklearn.datasets import load_diabetes\n", 11 | "\n", 12 | "import numpy as np\n", 13 | "from sklearn.linear_model import LinearRegression\n", 14 | "from sklearn.metrics import r2_score\n", 15 | "from sklearn.model_selection import train_test_split" 16 | ] 17 | }, 18 | { 19 | "cell_type": "code", 20 | "execution_count": 39, 21 | "id": "84500f46", 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [ 25 | "X,y = load_diabetes(return_X_y=True)" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 40, 31 | "id": "5ef471cc", 32 | "metadata": {}, 33 | "outputs": [ 34 | { 35 | "name": "stdout", 36 | "output_type": "stream", 37 | "text": [ 38 | "(442, 10)\n", 39 | "(442,)\n" 40 | ] 41 | } 42 | ], 43 | "source": [ 44 | "print(X.shape)\n", 45 | "print(y.shape)" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": 41, 51 | "id": "01ebedbc", 52 | "metadata": {}, 53 | "outputs": [], 54 | "source": [ 55 | "X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=2)" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": 42, 61 | "id": "3ab37e5e", 62 | "metadata": {}, 63 | "outputs": [ 64 | { 65 | "data": { 66 | "text/plain": [ 67 | "LinearRegression()" 68 | ] 69 | }, 70 | "execution_count": 42, 71 | "metadata": {}, 72 | "output_type": "execute_result" 73 | } 74 | ], 75 | "source": [ 76 | "reg = LinearRegression()\n", 77 | "reg.fit(X_train,y_train)" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 43, 83 | "id": "b0460e00", 84 | "metadata": {}, 85 | "outputs": [ 86 | { 87 | "name": "stdout", 88 | "output_type": "stream", 89 | "text": [ 90 | "[ -9.16088483 -205.46225988 516.68462383 340.62734108 -895.54360867\n", 91 | " 561.21453306 153.88478595 126.73431596 861.12139955 52.41982836]\n", 92 | "151.88334520854633\n" 93 | ] 94 | } 95 | ], 96 | "source": [ 97 | "print(reg.coef_)\n", 98 | "print(reg.intercept_)" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": 44, 104 | "id": "5c4104dd", 105 | "metadata": {}, 106 | "outputs": [ 107 | { 108 | "data": { 109 | "text/plain": [ 110 | "0.4399387660024645" 111 | ] 112 | }, 113 | "execution_count": 44, 114 | "metadata": {}, 115 | "output_type": "execute_result" 116 | } 117 | ], 118 | "source": [ 119 | "y_pred = reg.predict(X_test)\n", 120 | "r2_score(y_test,y_pred)" 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": 48, 126 | "id": "4d92f6d3", 127 | "metadata": {}, 128 | "outputs": [], 129 | "source": [ 130 | "import random\n", 131 | "\n", 132 | "class MBGDRegressor:\n", 133 | " \n", 134 | " def __init__(self,batch_size,learning_rate=0.01,epochs=100):\n", 135 | " \n", 136 | " self.coef_ = None\n", 137 | " self.intercept_ = None\n", 138 | " self.lr = learning_rate\n", 139 | " self.epochs = epochs\n", 140 | " self.batch_size = batch_size\n", 141 | " \n", 142 | " def fit(self,X_train,y_train):\n", 143 | " # init your coefs\n", 144 | " self.intercept_ = 0\n", 145 | " self.coef_ = np.ones(X_train.shape[1])\n", 146 | " \n", 147 | " for i in range(self.epochs):\n", 148 | " \n", 149 | " for j in range(int(X_train.shape[0]/self.batch_size)):\n", 150 | " \n", 151 | " idx = random.sample(range(X_train.shape[0]),self.batch_size)\n", 152 | " \n", 153 | " y_hat = np.dot(X_train[idx],self.coef_) + self.intercept_\n", 154 | " #print(\"Shape of y_hat\",y_hat.shape)\n", 155 | " intercept_der = -2 * np.mean(y_train[idx] - y_hat)\n", 156 | " self.intercept_ = self.intercept_ - (self.lr * intercept_der)\n", 157 | "\n", 158 | " coef_der = -2 * np.dot((y_train[idx] - y_hat),X_train[idx])\n", 159 | " self.coef_ = self.coef_ - (self.lr * coef_der)\n", 160 | " \n", 161 | " print(self.intercept_,self.coef_)\n", 162 | " \n", 163 | " def predict(self,X_test):\n", 164 | " return np.dot(X_test,self.coef_) + self.intercept_" 165 | ] 166 | }, 167 | { 168 | "cell_type": "code", 169 | "execution_count": 79, 170 | "id": "99078906", 171 | "metadata": {}, 172 | "outputs": [], 173 | "source": [ 174 | "mbr = MBGDRegressor(batch_size=int(X_train.shape[0]/50),learning_rate=0.01,epochs=100)" 175 | ] 176 | }, 177 | { 178 | "cell_type": "code", 179 | "execution_count": 80, 180 | "id": "dc4e8574", 181 | "metadata": {}, 182 | "outputs": [ 183 | { 184 | "name": "stdout", 185 | "output_type": "stream", 186 | "text": [ 187 | "154.83742294704174 [ 38.40848324 -142.67633481 457.28746444 303.60926403 -17.99961807\n", 188 | " -85.81943788 -192.04933133 116.18528414 407.24722272 105.8082595 ]\n" 189 | ] 190 | } 191 | ], 192 | "source": [ 193 | "mbr.fit(X_train,y_train)" 194 | ] 195 | }, 196 | { 197 | "cell_type": "code", 198 | "execution_count": 81, 199 | "id": "d32d9fef", 200 | "metadata": {}, 201 | "outputs": [], 202 | "source": [ 203 | "y_pred = mbr.predict(X_test)" 204 | ] 205 | }, 206 | { 207 | "cell_type": "code", 208 | "execution_count": 82, 209 | "id": "905a915d", 210 | "metadata": {}, 211 | "outputs": [ 212 | { 213 | "data": { 214 | "text/plain": [ 215 | "0.4518861449568681" 216 | ] 217 | }, 218 | "execution_count": 82, 219 | "metadata": {}, 220 | "output_type": "execute_result" 221 | } 222 | ], 223 | "source": [ 224 | "r2_score(y_test,y_pred)" 225 | ] 226 | }, 227 | { 228 | "cell_type": "code", 229 | "execution_count": 125, 230 | "id": "a48ecad9", 231 | "metadata": {}, 232 | "outputs": [], 233 | "source": [ 234 | "from sklearn.linear_model import SGDRegressor" 235 | ] 236 | }, 237 | { 238 | "cell_type": "code", 239 | "execution_count": 132, 240 | "id": "cc4d285f", 241 | "metadata": {}, 242 | "outputs": [], 243 | "source": [ 244 | "sgd = SGDRegressor(learning_rate='constant',eta0=0.1)" 245 | ] 246 | }, 247 | { 248 | "cell_type": "code", 249 | "execution_count": 133, 250 | "id": "23b8a8be", 251 | "metadata": {}, 252 | "outputs": [], 253 | "source": [ 254 | "batch_size = 35\n", 255 | "\n", 256 | "for i in range(100):\n", 257 | " \n", 258 | " idx = random.sample(range(X_train.shape[0]),batch_size)\n", 259 | " sgd.partial_fit(X_train[idx],y_train[idx])" 260 | ] 261 | }, 262 | { 263 | "cell_type": "code", 264 | "execution_count": 134, 265 | "id": "9827c50a", 266 | "metadata": {}, 267 | "outputs": [ 268 | { 269 | "data": { 270 | "text/plain": [ 271 | "array([ 49.19545821, -67.84533938, 338.57819421, 247.97315609,\n", 272 | " 25.30849249, -24.71685159, -155.45845777, 116.19331239,\n", 273 | " 312.91250811, 133.36595993])" 274 | ] 275 | }, 276 | "execution_count": 134, 277 | "metadata": {}, 278 | "output_type": "execute_result" 279 | } 280 | ], 281 | "source": [ 282 | "sgd.coef_" 283 | ] 284 | }, 285 | { 286 | "cell_type": "code", 287 | "execution_count": 135, 288 | "id": "bf5ae439", 289 | "metadata": {}, 290 | "outputs": [ 291 | { 292 | "data": { 293 | "text/plain": [ 294 | "array([148.61489911])" 295 | ] 296 | }, 297 | "execution_count": 135, 298 | "metadata": {}, 299 | "output_type": "execute_result" 300 | } 301 | ], 302 | "source": [ 303 | "sgd.intercept_" 304 | ] 305 | }, 306 | { 307 | "cell_type": "code", 308 | "execution_count": 136, 309 | "id": "df9c2619", 310 | "metadata": {}, 311 | "outputs": [], 312 | "source": [ 313 | "y_pred = sgd.predict(X_test)" 314 | ] 315 | }, 316 | { 317 | "cell_type": "code", 318 | "execution_count": 137, 319 | "id": "ab5ea374", 320 | "metadata": {}, 321 | "outputs": [ 322 | { 323 | "data": { 324 | "text/plain": [ 325 | "0.4271789125617129" 326 | ] 327 | }, 328 | "execution_count": 137, 329 | "metadata": {}, 330 | "output_type": "execute_result" 331 | } 332 | ], 333 | "source": [ 334 | "r2_score(y_test,y_pred)" 335 | ] 336 | }, 337 | { 338 | "cell_type": "code", 339 | "execution_count": null, 340 | "id": "8b8d5010", 341 | "metadata": {}, 342 | "outputs": [], 343 | "source": [] 344 | }, 345 | { 346 | "cell_type": "code", 347 | "execution_count": null, 348 | "id": "d213087b", 349 | "metadata": {}, 350 | "outputs": [], 351 | "source": [] 352 | } 353 | ], 354 | "metadata": { 355 | "kernelspec": { 356 | "display_name": "Python 3", 357 | "language": "python", 358 | "name": "python3" 359 | }, 360 | "language_info": { 361 | "codemirror_mode": { 362 | "name": "ipython", 363 | "version": 3 364 | }, 365 | "file_extension": ".py", 366 | "mimetype": "text/x-python", 367 | "name": "python", 368 | "nbconvert_exporter": "python", 369 | "pygments_lexer": "ipython3", 370 | "version": "3.8.8" 371 | } 372 | }, 373 | "nbformat": 4, 374 | "nbformat_minor": 5 375 | } 376 | -------------------------------------------------------------------------------- /day25-normalization/wine_data.csv: -------------------------------------------------------------------------------- 1 | 1,14.23,1.71,2.43,15.6,127,2.8,3.06,.28,2.29,5.64,1.04,3.92,1065 2 | 1,13.2,1.78,2.14,11.2,100,2.65,2.76,.26,1.28,4.38,1.05,3.4,1050 3 | 1,13.16,2.36,2.67,18.6,101,2.8,3.24,.3,2.81,5.68,1.03,3.17,1185 4 | 1,14.37,1.95,2.5,16.8,113,3.85,3.49,.24,2.18,7.8,.86,3.45,1480 5 | 1,13.24,2.59,2.87,21,118,2.8,2.69,.39,1.82,4.32,1.04,2.93,735 6 | 1,14.2,1.76,2.45,15.2,112,3.27,3.39,.34,1.97,6.75,1.05,2.85,1450 7 | 1,14.39,1.87,2.45,14.6,96,2.5,2.52,.3,1.98,5.25,1.02,3.58,1290 8 | 1,14.06,2.15,2.61,17.6,121,2.6,2.51,.31,1.25,5.05,1.06,3.58,1295 9 | 1,14.83,1.64,2.17,14,97,2.8,2.98,.29,1.98,5.2,1.08,2.85,1045 10 | 1,13.86,1.35,2.27,16,98,2.98,3.15,.22,1.85,7.22,1.01,3.55,1045 11 | 1,14.1,2.16,2.3,18,105,2.95,3.32,.22,2.38,5.75,1.25,3.17,1510 12 | 1,14.12,1.48,2.32,16.8,95,2.2,2.43,.26,1.57,5,1.17,2.82,1280 13 | 1,13.75,1.73,2.41,16,89,2.6,2.76,.29,1.81,5.6,1.15,2.9,1320 14 | 1,14.75,1.73,2.39,11.4,91,3.1,3.69,.43,2.81,5.4,1.25,2.73,1150 15 | 1,14.38,1.87,2.38,12,102,3.3,3.64,.29,2.96,7.5,1.2,3,1547 16 | 1,13.63,1.81,2.7,17.2,112,2.85,2.91,.3,1.46,7.3,1.28,2.88,1310 17 | 1,14.3,1.92,2.72,20,120,2.8,3.14,.33,1.97,6.2,1.07,2.65,1280 18 | 1,13.83,1.57,2.62,20,115,2.95,3.4,.4,1.72,6.6,1.13,2.57,1130 19 | 1,14.19,1.59,2.48,16.5,108,3.3,3.93,.32,1.86,8.7,1.23,2.82,1680 20 | 1,13.64,3.1,2.56,15.2,116,2.7,3.03,.17,1.66,5.1,.96,3.36,845 21 | 1,14.06,1.63,2.28,16,126,3,3.17,.24,2.1,5.65,1.09,3.71,780 22 | 1,12.93,3.8,2.65,18.6,102,2.41,2.41,.25,1.98,4.5,1.03,3.52,770 23 | 1,13.71,1.86,2.36,16.6,101,2.61,2.88,.27,1.69,3.8,1.11,4,1035 24 | 1,12.85,1.6,2.52,17.8,95,2.48,2.37,.26,1.46,3.93,1.09,3.63,1015 25 | 1,13.5,1.81,2.61,20,96,2.53,2.61,.28,1.66,3.52,1.12,3.82,845 26 | 1,13.05,2.05,3.22,25,124,2.63,2.68,.47,1.92,3.58,1.13,3.2,830 27 | 1,13.39,1.77,2.62,16.1,93,2.85,2.94,.34,1.45,4.8,.92,3.22,1195 28 | 1,13.3,1.72,2.14,17,94,2.4,2.19,.27,1.35,3.95,1.02,2.77,1285 29 | 1,13.87,1.9,2.8,19.4,107,2.95,2.97,.37,1.76,4.5,1.25,3.4,915 30 | 1,14.02,1.68,2.21,16,96,2.65,2.33,.26,1.98,4.7,1.04,3.59,1035 31 | 1,13.73,1.5,2.7,22.5,101,3,3.25,.29,2.38,5.7,1.19,2.71,1285 32 | 1,13.58,1.66,2.36,19.1,106,2.86,3.19,.22,1.95,6.9,1.09,2.88,1515 33 | 1,13.68,1.83,2.36,17.2,104,2.42,2.69,.42,1.97,3.84,1.23,2.87,990 34 | 1,13.76,1.53,2.7,19.5,132,2.95,2.74,.5,1.35,5.4,1.25,3,1235 35 | 1,13.51,1.8,2.65,19,110,2.35,2.53,.29,1.54,4.2,1.1,2.87,1095 36 | 1,13.48,1.81,2.41,20.5,100,2.7,2.98,.26,1.86,5.1,1.04,3.47,920 37 | 1,13.28,1.64,2.84,15.5,110,2.6,2.68,.34,1.36,4.6,1.09,2.78,880 38 | 1,13.05,1.65,2.55,18,98,2.45,2.43,.29,1.44,4.25,1.12,2.51,1105 39 | 1,13.07,1.5,2.1,15.5,98,2.4,2.64,.28,1.37,3.7,1.18,2.69,1020 40 | 1,14.22,3.99,2.51,13.2,128,3,3.04,.2,2.08,5.1,.89,3.53,760 41 | 1,13.56,1.71,2.31,16.2,117,3.15,3.29,.34,2.34,6.13,.95,3.38,795 42 | 1,13.41,3.84,2.12,18.8,90,2.45,2.68,.27,1.48,4.28,.91,3,1035 43 | 1,13.88,1.89,2.59,15,101,3.25,3.56,.17,1.7,5.43,.88,3.56,1095 44 | 1,13.24,3.98,2.29,17.5,103,2.64,2.63,.32,1.66,4.36,.82,3,680 45 | 1,13.05,1.77,2.1,17,107,3,3,.28,2.03,5.04,.88,3.35,885 46 | 1,14.21,4.04,2.44,18.9,111,2.85,2.65,.3,1.25,5.24,.87,3.33,1080 47 | 1,14.38,3.59,2.28,16,102,3.25,3.17,.27,2.19,4.9,1.04,3.44,1065 48 | 1,13.9,1.68,2.12,16,101,3.1,3.39,.21,2.14,6.1,.91,3.33,985 49 | 1,14.1,2.02,2.4,18.8,103,2.75,2.92,.32,2.38,6.2,1.07,2.75,1060 50 | 1,13.94,1.73,2.27,17.4,108,2.88,3.54,.32,2.08,8.90,1.12,3.1,1260 51 | 1,13.05,1.73,2.04,12.4,92,2.72,3.27,.17,2.91,7.2,1.12,2.91,1150 52 | 1,13.83,1.65,2.6,17.2,94,2.45,2.99,.22,2.29,5.6,1.24,3.37,1265 53 | 1,13.82,1.75,2.42,14,111,3.88,3.74,.32,1.87,7.05,1.01,3.26,1190 54 | 1,13.77,1.9,2.68,17.1,115,3,2.79,.39,1.68,6.3,1.13,2.93,1375 55 | 1,13.74,1.67,2.25,16.4,118,2.6,2.9,.21,1.62,5.85,.92,3.2,1060 56 | 1,13.56,1.73,2.46,20.5,116,2.96,2.78,.2,2.45,6.25,.98,3.03,1120 57 | 1,14.22,1.7,2.3,16.3,118,3.2,3,.26,2.03,6.38,.94,3.31,970 58 | 1,13.29,1.97,2.68,16.8,102,3,3.23,.31,1.66,6,1.07,2.84,1270 59 | 1,13.72,1.43,2.5,16.7,108,3.4,3.67,.19,2.04,6.8,.89,2.87,1285 60 | 2,12.37,.94,1.36,10.6,88,1.98,.57,.28,.42,1.95,1.05,1.82,520 61 | 2,12.33,1.1,2.28,16,101,2.05,1.09,.63,.41,3.27,1.25,1.67,680 62 | 2,12.64,1.36,2.02,16.8,100,2.02,1.41,.53,.62,5.75,.98,1.59,450 63 | 2,13.67,1.25,1.92,18,94,2.1,1.79,.32,.73,3.8,1.23,2.46,630 64 | 2,12.37,1.13,2.16,19,87,3.5,3.1,.19,1.87,4.45,1.22,2.87,420 65 | 2,12.17,1.45,2.53,19,104,1.89,1.75,.45,1.03,2.95,1.45,2.23,355 66 | 2,12.37,1.21,2.56,18.1,98,2.42,2.65,.37,2.08,4.6,1.19,2.3,678 67 | 2,13.11,1.01,1.7,15,78,2.98,3.18,.26,2.28,5.3,1.12,3.18,502 68 | 2,12.37,1.17,1.92,19.6,78,2.11,2,.27,1.04,4.68,1.12,3.48,510 69 | 2,13.34,.94,2.36,17,110,2.53,1.3,.55,.42,3.17,1.02,1.93,750 70 | 2,12.21,1.19,1.75,16.8,151,1.85,1.28,.14,2.5,2.85,1.28,3.07,718 71 | 2,12.29,1.61,2.21,20.4,103,1.1,1.02,.37,1.46,3.05,.906,1.82,870 72 | 2,13.86,1.51,2.67,25,86,2.95,2.86,.21,1.87,3.38,1.36,3.16,410 73 | 2,13.49,1.66,2.24,24,87,1.88,1.84,.27,1.03,3.74,.98,2.78,472 74 | 2,12.99,1.67,2.6,30,139,3.3,2.89,.21,1.96,3.35,1.31,3.5,985 75 | 2,11.96,1.09,2.3,21,101,3.38,2.14,.13,1.65,3.21,.99,3.13,886 76 | 2,11.66,1.88,1.92,16,97,1.61,1.57,.34,1.15,3.8,1.23,2.14,428 77 | 2,13.03,.9,1.71,16,86,1.95,2.03,.24,1.46,4.6,1.19,2.48,392 78 | 2,11.84,2.89,2.23,18,112,1.72,1.32,.43,.95,2.65,.96,2.52,500 79 | 2,12.33,.99,1.95,14.8,136,1.9,1.85,.35,2.76,3.4,1.06,2.31,750 80 | 2,12.7,3.87,2.4,23,101,2.83,2.55,.43,1.95,2.57,1.19,3.13,463 81 | 2,12,.92,2,19,86,2.42,2.26,.3,1.43,2.5,1.38,3.12,278 82 | 2,12.72,1.81,2.2,18.8,86,2.2,2.53,.26,1.77,3.9,1.16,3.14,714 83 | 2,12.08,1.13,2.51,24,78,2,1.58,.4,1.4,2.2,1.31,2.72,630 84 | 2,13.05,3.86,2.32,22.5,85,1.65,1.59,.61,1.62,4.8,.84,2.01,515 85 | 2,11.84,.89,2.58,18,94,2.2,2.21,.22,2.35,3.05,.79,3.08,520 86 | 2,12.67,.98,2.24,18,99,2.2,1.94,.3,1.46,2.62,1.23,3.16,450 87 | 2,12.16,1.61,2.31,22.8,90,1.78,1.69,.43,1.56,2.45,1.33,2.26,495 88 | 2,11.65,1.67,2.62,26,88,1.92,1.61,.4,1.34,2.6,1.36,3.21,562 89 | 2,11.64,2.06,2.46,21.6,84,1.95,1.69,.48,1.35,2.8,1,2.75,680 90 | 2,12.08,1.33,2.3,23.6,70,2.2,1.59,.42,1.38,1.74,1.07,3.21,625 91 | 2,12.08,1.83,2.32,18.5,81,1.6,1.5,.52,1.64,2.4,1.08,2.27,480 92 | 2,12,1.51,2.42,22,86,1.45,1.25,.5,1.63,3.6,1.05,2.65,450 93 | 2,12.69,1.53,2.26,20.7,80,1.38,1.46,.58,1.62,3.05,.96,2.06,495 94 | 2,12.29,2.83,2.22,18,88,2.45,2.25,.25,1.99,2.15,1.15,3.3,290 95 | 2,11.62,1.99,2.28,18,98,3.02,2.26,.17,1.35,3.25,1.16,2.96,345 96 | 2,12.47,1.52,2.2,19,162,2.5,2.27,.32,3.28,2.6,1.16,2.63,937 97 | 2,11.81,2.12,2.74,21.5,134,1.6,.99,.14,1.56,2.5,.95,2.26,625 98 | 2,12.29,1.41,1.98,16,85,2.55,2.5,.29,1.77,2.9,1.23,2.74,428 99 | 2,12.37,1.07,2.1,18.5,88,3.52,3.75,.24,1.95,4.5,1.04,2.77,660 100 | 2,12.29,3.17,2.21,18,88,2.85,2.99,.45,2.81,2.3,1.42,2.83,406 101 | 2,12.08,2.08,1.7,17.5,97,2.23,2.17,.26,1.4,3.3,1.27,2.96,710 102 | 2,12.6,1.34,1.9,18.5,88,1.45,1.36,.29,1.35,2.45,1.04,2.77,562 103 | 2,12.34,2.45,2.46,21,98,2.56,2.11,.34,1.31,2.8,.8,3.38,438 104 | 2,11.82,1.72,1.88,19.5,86,2.5,1.64,.37,1.42,2.06,.94,2.44,415 105 | 2,12.51,1.73,1.98,20.5,85,2.2,1.92,.32,1.48,2.94,1.04,3.57,672 106 | 2,12.42,2.55,2.27,22,90,1.68,1.84,.66,1.42,2.7,.86,3.3,315 107 | 2,12.25,1.73,2.12,19,80,1.65,2.03,.37,1.63,3.4,1,3.17,510 108 | 2,12.72,1.75,2.28,22.5,84,1.38,1.76,.48,1.63,3.3,.88,2.42,488 109 | 2,12.22,1.29,1.94,19,92,2.36,2.04,.39,2.08,2.7,.86,3.02,312 110 | 2,11.61,1.35,2.7,20,94,2.74,2.92,.29,2.49,2.65,.96,3.26,680 111 | 2,11.46,3.74,1.82,19.5,107,3.18,2.58,.24,3.58,2.9,.75,2.81,562 112 | 2,12.52,2.43,2.17,21,88,2.55,2.27,.26,1.22,2,.9,2.78,325 113 | 2,11.76,2.68,2.92,20,103,1.75,2.03,.6,1.05,3.8,1.23,2.5,607 114 | 2,11.41,.74,2.5,21,88,2.48,2.01,.42,1.44,3.08,1.1,2.31,434 115 | 2,12.08,1.39,2.5,22.5,84,2.56,2.29,.43,1.04,2.9,.93,3.19,385 116 | 2,11.03,1.51,2.2,21.5,85,2.46,2.17,.52,2.01,1.9,1.71,2.87,407 117 | 2,11.82,1.47,1.99,20.8,86,1.98,1.6,.3,1.53,1.95,.95,3.33,495 118 | 2,12.42,1.61,2.19,22.5,108,2,2.09,.34,1.61,2.06,1.06,2.96,345 119 | 2,12.77,3.43,1.98,16,80,1.63,1.25,.43,.83,3.4,.7,2.12,372 120 | 2,12,3.43,2,19,87,2,1.64,.37,1.87,1.28,.93,3.05,564 121 | 2,11.45,2.4,2.42,20,96,2.9,2.79,.32,1.83,3.25,.8,3.39,625 122 | 2,11.56,2.05,3.23,28.5,119,3.18,5.08,.47,1.87,6,.93,3.69,465 123 | 2,12.42,4.43,2.73,26.5,102,2.2,2.13,.43,1.71,2.08,.92,3.12,365 124 | 2,13.05,5.8,2.13,21.5,86,2.62,2.65,.3,2.01,2.6,.73,3.1,380 125 | 2,11.87,4.31,2.39,21,82,2.86,3.03,.21,2.91,2.8,.75,3.64,380 126 | 2,12.07,2.16,2.17,21,85,2.6,2.65,.37,1.35,2.76,.86,3.28,378 127 | 2,12.43,1.53,2.29,21.5,86,2.74,3.15,.39,1.77,3.94,.69,2.84,352 128 | 2,11.79,2.13,2.78,28.5,92,2.13,2.24,.58,1.76,3,.97,2.44,466 129 | 2,12.37,1.63,2.3,24.5,88,2.22,2.45,.4,1.9,2.12,.89,2.78,342 130 | 2,12.04,4.3,2.38,22,80,2.1,1.75,.42,1.35,2.6,.79,2.57,580 131 | 3,12.86,1.35,2.32,18,122,1.51,1.25,.21,.94,4.1,.76,1.29,630 132 | 3,12.88,2.99,2.4,20,104,1.3,1.22,.24,.83,5.4,.74,1.42,530 133 | 3,12.81,2.31,2.4,24,98,1.15,1.09,.27,.83,5.7,.66,1.36,560 134 | 3,12.7,3.55,2.36,21.5,106,1.7,1.2,.17,.84,5,.78,1.29,600 135 | 3,12.51,1.24,2.25,17.5,85,2,.58,.6,1.25,5.45,.75,1.51,650 136 | 3,12.6,2.46,2.2,18.5,94,1.62,.66,.63,.94,7.1,.73,1.58,695 137 | 3,12.25,4.72,2.54,21,89,1.38,.47,.53,.8,3.85,.75,1.27,720 138 | 3,12.53,5.51,2.64,25,96,1.79,.6,.63,1.1,5,.82,1.69,515 139 | 3,13.49,3.59,2.19,19.5,88,1.62,.48,.58,.88,5.7,.81,1.82,580 140 | 3,12.84,2.96,2.61,24,101,2.32,.6,.53,.81,4.92,.89,2.15,590 141 | 3,12.93,2.81,2.7,21,96,1.54,.5,.53,.75,4.6,.77,2.31,600 142 | 3,13.36,2.56,2.35,20,89,1.4,.5,.37,.64,5.6,.7,2.47,780 143 | 3,13.52,3.17,2.72,23.5,97,1.55,.52,.5,.55,4.35,.89,2.06,520 144 | 3,13.62,4.95,2.35,20,92,2,.8,.47,1.02,4.4,.91,2.05,550 145 | 3,12.25,3.88,2.2,18.5,112,1.38,.78,.29,1.14,8.21,.65,2,855 146 | 3,13.16,3.57,2.15,21,102,1.5,.55,.43,1.3,4,.6,1.68,830 147 | 3,13.88,5.04,2.23,20,80,.98,.34,.4,.68,4.9,.58,1.33,415 148 | 3,12.87,4.61,2.48,21.5,86,1.7,.65,.47,.86,7.65,.54,1.86,625 149 | 3,13.32,3.24,2.38,21.5,92,1.93,.76,.45,1.25,8.42,.55,1.62,650 150 | 3,13.08,3.9,2.36,21.5,113,1.41,1.39,.34,1.14,9.40,.57,1.33,550 151 | 3,13.5,3.12,2.62,24,123,1.4,1.57,.22,1.25,8.60,.59,1.3,500 152 | 3,12.79,2.67,2.48,22,112,1.48,1.36,.24,1.26,10.8,.48,1.47,480 153 | 3,13.11,1.9,2.75,25.5,116,2.2,1.28,.26,1.56,7.1,.61,1.33,425 154 | 3,13.23,3.3,2.28,18.5,98,1.8,.83,.61,1.87,10.52,.56,1.51,675 155 | 3,12.58,1.29,2.1,20,103,1.48,.58,.53,1.4,7.6,.58,1.55,640 156 | 3,13.17,5.19,2.32,22,93,1.74,.63,.61,1.55,7.9,.6,1.48,725 157 | 3,13.84,4.12,2.38,19.5,89,1.8,.83,.48,1.56,9.01,.57,1.64,480 158 | 3,12.45,3.03,2.64,27,97,1.9,.58,.63,1.14,7.5,.67,1.73,880 159 | 3,14.34,1.68,2.7,25,98,2.8,1.31,.53,2.7,13,.57,1.96,660 160 | 3,13.48,1.67,2.64,22.5,89,2.6,1.1,.52,2.29,11.75,.57,1.78,620 161 | 3,12.36,3.83,2.38,21,88,2.3,.92,.5,1.04,7.65,.56,1.58,520 162 | 3,13.69,3.26,2.54,20,107,1.83,.56,.5,.8,5.88,.96,1.82,680 163 | 3,12.85,3.27,2.58,22,106,1.65,.6,.6,.96,5.58,.87,2.11,570 164 | 3,12.96,3.45,2.35,18.5,106,1.39,.7,.4,.94,5.28,.68,1.75,675 165 | 3,13.78,2.76,2.3,22,90,1.35,.68,.41,1.03,9.58,.7,1.68,615 166 | 3,13.73,4.36,2.26,22.5,88,1.28,.47,.52,1.15,6.62,.78,1.75,520 167 | 3,13.45,3.7,2.6,23,111,1.7,.92,.43,1.46,10.68,.85,1.56,695 168 | 3,12.82,3.37,2.3,19.5,88,1.48,.66,.4,.97,10.26,.72,1.75,685 169 | 3,13.58,2.58,2.69,24.5,105,1.55,.84,.39,1.54,8.66,.74,1.8,750 170 | 3,13.4,4.6,2.86,25,112,1.98,.96,.27,1.11,8.5,.67,1.92,630 171 | 3,12.2,3.03,2.32,19,96,1.25,.49,.4,.73,5.5,.66,1.83,510 172 | 3,12.77,2.39,2.28,19.5,86,1.39,.51,.48,.64,9.899999,.57,1.63,470 173 | 3,14.16,2.51,2.48,20,91,1.68,.7,.44,1.24,9.7,.62,1.71,660 174 | 3,13.71,5.65,2.45,20.5,95,1.68,.61,.52,1.06,7.7,.64,1.74,740 175 | 3,13.4,3.91,2.48,23,102,1.8,.75,.43,1.41,7.3,.7,1.56,750 176 | 3,13.27,4.28,2.26,20,120,1.59,.69,.43,1.35,10.2,.59,1.56,835 177 | 3,13.17,2.59,2.37,20,120,1.65,.68,.53,1.46,9.3,.6,1.62,840 178 | 3,14.13,4.1,2.74,24.5,96,2.05,.76,.56,1.35,9.2,.61,1.6,560 179 | -------------------------------------------------------------------------------- /day48-simple-linear-regression/Untitled1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 120, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "class MeraLR:\n", 10 | " \n", 11 | " def __init__(self):\n", 12 | " self.m = None\n", 13 | " self.b = None\n", 14 | " \n", 15 | " def fit(self,X_train,y_train):\n", 16 | " \n", 17 | " num = 0\n", 18 | " den = 0\n", 19 | " \n", 20 | " for i in range(X_train.shape[0]):\n", 21 | " \n", 22 | " num = num + ((X_train[i] - X_train.mean())*(y_train[i] - y_train.mean()))\n", 23 | " den = den + ((X_train[i] - X_train.mean())*(X_train[i] - X_train.mean()))\n", 24 | " \n", 25 | " self.m = num/den\n", 26 | " self.b = y_train.mean() - (self.m * X_train.mean())\n", 27 | " print(self.m)\n", 28 | " print(self.b) \n", 29 | " \n", 30 | " def predict(self,X_test):\n", 31 | " \n", 32 | " print(X_test)\n", 33 | " \n", 34 | " return self.m * X_test + self.b" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": 94, 40 | "metadata": {}, 41 | "outputs": [], 42 | "source": [ 43 | "import numpy as np\n", 44 | "import pandas as pd" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 95, 50 | "metadata": {}, 51 | "outputs": [], 52 | "source": [ 53 | "df = pd.read_csv('placement.csv')" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": 96, 59 | "metadata": {}, 60 | "outputs": [ 61 | { 62 | "data": { 63 | "text/html": [ 64 | "
\n", 65 | "\n", 78 | "\n", 79 | " \n", 80 | " \n", 81 | " \n", 82 | " \n", 83 | " \n", 84 | " \n", 85 | " \n", 86 | " \n", 87 | " \n", 88 | " \n", 89 | " \n", 90 | " \n", 91 | " \n", 92 | " \n", 93 | " \n", 94 | " \n", 95 | " \n", 96 | " \n", 97 | " \n", 98 | " \n", 99 | " \n", 100 | " \n", 101 | " \n", 102 | " \n", 103 | " \n", 104 | " \n", 105 | " \n", 106 | " \n", 107 | " \n", 108 | " \n", 109 | " \n", 110 | " \n", 111 | " \n", 112 | " \n", 113 | "
cgpapackage
06.893.26
15.121.98
27.823.25
37.423.67
46.943.57
\n", 114 | "
" 115 | ], 116 | "text/plain": [ 117 | " cgpa package\n", 118 | "0 6.89 3.26\n", 119 | "1 5.12 1.98\n", 120 | "2 7.82 3.25\n", 121 | "3 7.42 3.67\n", 122 | "4 6.94 3.57" 123 | ] 124 | }, 125 | "execution_count": 96, 126 | "metadata": {}, 127 | "output_type": "execute_result" 128 | } 129 | ], 130 | "source": [ 131 | "df.head()" 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": 97, 137 | "metadata": {}, 138 | "outputs": [], 139 | "source": [ 140 | "X = df.iloc[:,0].values\n", 141 | "y = df.iloc[:,1].values" 142 | ] 143 | }, 144 | { 145 | "cell_type": "code", 146 | "execution_count": 98, 147 | "metadata": {}, 148 | "outputs": [ 149 | { 150 | "data": { 151 | "text/plain": [ 152 | "array([6.89, 5.12, 7.82, 7.42, 6.94, 7.89, 6.73, 6.75, 6.09, 8.31, 5.32,\n", 153 | " 6.61, 8.94, 6.93, 7.73, 7.25, 6.84, 5.38, 6.94, 7.48, 7.28, 6.85,\n", 154 | " 6.14, 6.19, 6.53, 7.28, 8.31, 5.42, 5.94, 7.15, 7.36, 8.1 , 6.96,\n", 155 | " 6.35, 7.34, 6.87, 5.99, 5.9 , 8.62, 7.43, 9.38, 6.89, 5.95, 7.66,\n", 156 | " 5.09, 7.87, 6.07, 5.84, 8.63, 8.87, 9.58, 9.26, 8.37, 6.47, 6.86,\n", 157 | " 8.2 , 5.84, 6.6 , 6.92, 7.56, 5.61, 5.48, 6.34, 9.16, 7.36, 7.6 ,\n", 158 | " 5.11, 6.51, 7.56, 7.3 , 5.79, 7.47, 7.78, 8.44, 6.85, 6.97, 6.94,\n", 159 | " 8.99, 6.59, 7.18, 7.63, 6.1 , 5.58, 8.44, 4.26, 4.79, 7.61, 8.09,\n", 160 | " 4.73, 6.42, 7.11, 6.22, 7.9 , 6.79, 5.83, 6.63, 7.11, 5.98, 7.69,\n", 161 | " 6.61, 7.95, 6.71, 5.13, 7.05, 7.62, 6.66, 6.13, 6.33, 7.76, 7.77,\n", 162 | " 8.18, 5.42, 8.58, 6.94, 5.84, 8.35, 9.04, 7.12, 7.4 , 7.39, 5.23,\n", 163 | " 6.5 , 5.12, 5.1 , 6.06, 7.33, 5.91, 6.78, 7.93, 7.29, 6.68, 6.37,\n", 164 | " 5.84, 6.05, 7.2 , 6.1 , 5.64, 7.14, 7.91, 7.19, 7.91, 6.76, 6.93,\n", 165 | " 4.85, 6.17, 5.84, 6.07, 5.66, 7.57, 8.28, 6.3 , 6.12, 7.37, 7.94,\n", 166 | " 7.08, 6.98, 7.38, 6.47, 5.95, 8.71, 7.13, 7.3 , 5.53, 8.93, 9.06,\n", 167 | " 8.21, 8.6 , 8.13, 8.65, 9.31, 6.22, 8.01, 6.93, 6.75, 7.32, 7.04,\n", 168 | " 6.29, 7.09, 8.15, 7.14, 6.19, 8.22, 5.88, 7.28, 7.88, 6.31, 7.84,\n", 169 | " 6.26, 7.35, 8.11, 6.19, 7.28, 8.25, 4.57, 7.89, 6.93, 5.89, 7.21,\n", 170 | " 7.63, 6.22])" 171 | ] 172 | }, 173 | "execution_count": 98, 174 | "metadata": {}, 175 | "output_type": "execute_result" 176 | } 177 | ], 178 | "source": [ 179 | "X" 180 | ] 181 | }, 182 | { 183 | "cell_type": "code", 184 | "execution_count": 99, 185 | "metadata": {}, 186 | "outputs": [ 187 | { 188 | "data": { 189 | "text/plain": [ 190 | "array([3.26, 1.98, 3.25, 3.67, 3.57, 2.99, 2.6 , 2.48, 2.31, 3.51, 1.86,\n", 191 | " 2.6 , 3.65, 2.89, 3.42, 3.23, 2.35, 2.09, 2.98, 2.83, 3.16, 2.93,\n", 192 | " 2.3 , 2.48, 2.71, 3.65, 3.42, 2.16, 2.24, 3.49, 3.26, 3.89, 3.08,\n", 193 | " 2.73, 3.42, 2.87, 2.84, 2.43, 4.36, 3.33, 4.02, 2.7 , 2.54, 2.76,\n", 194 | " 1.86, 3.58, 2.26, 3.26, 4.09, 4.62, 4.43, 3.79, 4.11, 2.61, 3.09,\n", 195 | " 3.39, 2.74, 1.94, 3.09, 3.31, 2.19, 1.61, 2.09, 4.25, 2.92, 3.81,\n", 196 | " 1.63, 2.89, 2.99, 2.94, 2.35, 3.34, 3.62, 4.03, 3.44, 3.28, 3.15,\n", 197 | " 4.6 , 2.21, 3. , 3.44, 2.2 , 2.17, 3.49, 1.53, 1.48, 2.77, 3.55,\n", 198 | " 1.48, 2.72, 2.66, 2.14, 4. , 3.08, 2.42, 2.79, 2.61, 2.84, 3.83,\n", 199 | " 3.24, 4.14, 3.52, 1.37, 3. , 3.74, 2.82, 2.19, 2.59, 3.54, 4.06,\n", 200 | " 3.76, 2.25, 4.1 , 2.37, 1.87, 4.21, 3.33, 2.99, 2.88, 2.65, 1.73,\n", 201 | " 3.02, 2.01, 2.3 , 2.31, 3.16, 2.6 , 3.11, 3.34, 3.12, 2.49, 2.01,\n", 202 | " 2.48, 2.58, 2.83, 2.6 , 2.1 , 3.13, 3.89, 2.4 , 3.15, 3.18, 3.04,\n", 203 | " 1.54, 2.42, 2.18, 2.46, 2.21, 3.4 , 3.67, 2.73, 2.76, 3.08, 3.99,\n", 204 | " 2.85, 3.09, 3.13, 2.7 , 3.04, 4.08, 2.93, 3.33, 2.55, 3.91, 3.82,\n", 205 | " 4.08, 3.98, 3.6 , 3.52, 4.37, 2.87, 3.76, 2.51, 2.56, 2.99, 3.5 ,\n", 206 | " 3.23, 3.64, 3.63, 3.03, 2.72, 3.89, 2.08, 2.72, 3.14, 3.18, 3.47,\n", 207 | " 2.44, 3.08, 4.06, 2.69, 3.48, 3.75, 1.94, 3.67, 2.46, 2.57, 3.24,\n", 208 | " 3.96, 2.33])" 209 | ] 210 | }, 211 | "execution_count": 99, 212 | "metadata": {}, 213 | "output_type": "execute_result" 214 | } 215 | ], 216 | "source": [ 217 | "y" 218 | ] 219 | }, 220 | { 221 | "cell_type": "code", 222 | "execution_count": 100, 223 | "metadata": {}, 224 | "outputs": [], 225 | "source": [ 226 | "from sklearn.model_selection import train_test_split\n", 227 | "X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=2)" 228 | ] 229 | }, 230 | { 231 | "cell_type": "code", 232 | "execution_count": 102, 233 | "metadata": {}, 234 | "outputs": [ 235 | { 236 | "data": { 237 | "text/plain": [ 238 | "(160,)" 239 | ] 240 | }, 241 | "execution_count": 102, 242 | "metadata": {}, 243 | "output_type": "execute_result" 244 | } 245 | ], 246 | "source": [ 247 | "X_train.shape" 248 | ] 249 | }, 250 | { 251 | "cell_type": "code", 252 | "execution_count": 122, 253 | "metadata": {}, 254 | "outputs": [], 255 | "source": [ 256 | "lr = MeraLR()" 257 | ] 258 | }, 259 | { 260 | "cell_type": "code", 261 | "execution_count": 123, 262 | "metadata": {}, 263 | "outputs": [ 264 | { 265 | "name": "stdout", 266 | "output_type": "stream", 267 | "text": [ 268 | "0.5579519734250721\n", 269 | "-0.8961119222429152\n" 270 | ] 271 | } 272 | ], 273 | "source": [ 274 | "lr.fit(X_train,y_train)" 275 | ] 276 | }, 277 | { 278 | "cell_type": "code", 279 | "execution_count": 105, 280 | "metadata": {}, 281 | "outputs": [ 282 | { 283 | "data": { 284 | "text/plain": [ 285 | "160" 286 | ] 287 | }, 288 | "execution_count": 105, 289 | "metadata": {}, 290 | "output_type": "execute_result" 291 | } 292 | ], 293 | "source": [ 294 | "X_train.shape[0]" 295 | ] 296 | }, 297 | { 298 | "cell_type": "code", 299 | "execution_count": 106, 300 | "metadata": {}, 301 | "outputs": [ 302 | { 303 | "data": { 304 | "text/plain": [ 305 | "7.14" 306 | ] 307 | }, 308 | "execution_count": 106, 309 | "metadata": {}, 310 | "output_type": "execute_result" 311 | } 312 | ], 313 | "source": [ 314 | "X_train[0]" 315 | ] 316 | }, 317 | { 318 | "cell_type": "code", 319 | "execution_count": 108, 320 | "metadata": {}, 321 | "outputs": [ 322 | { 323 | "data": { 324 | "text/plain": [ 325 | "6.989937500000001" 326 | ] 327 | }, 328 | "execution_count": 108, 329 | "metadata": {}, 330 | "output_type": "execute_result" 331 | } 332 | ], 333 | "source": [ 334 | "X_train.mean()" 335 | ] 336 | }, 337 | { 338 | "cell_type": "code", 339 | "execution_count": 117, 340 | "metadata": {}, 341 | "outputs": [ 342 | { 343 | "data": { 344 | "text/plain": [ 345 | "8.58" 346 | ] 347 | }, 348 | "execution_count": 117, 349 | "metadata": {}, 350 | "output_type": "execute_result" 351 | } 352 | ], 353 | "source": [ 354 | "X_test[0]" 355 | ] 356 | }, 357 | { 358 | "cell_type": "code", 359 | "execution_count": 124, 360 | "metadata": {}, 361 | "outputs": [ 362 | { 363 | "name": "stdout", 364 | "output_type": "stream", 365 | "text": [ 366 | "8.58\n", 367 | "3.891116009744203\n" 368 | ] 369 | } 370 | ], 371 | "source": [ 372 | "print(lr.predict(X_test[0]))" 373 | ] 374 | }, 375 | { 376 | "cell_type": "code", 377 | "execution_count": null, 378 | "metadata": {}, 379 | "outputs": [], 380 | "source": [] 381 | } 382 | ], 383 | "metadata": { 384 | "kernelspec": { 385 | "display_name": "Python 3", 386 | "language": "python", 387 | "name": "python3" 388 | }, 389 | "language_info": { 390 | "codemirror_mode": { 391 | "name": "ipython", 392 | "version": 3 393 | }, 394 | "file_extension": ".py", 395 | "mimetype": "text/x-python", 396 | "name": "python", 397 | "nbconvert_exporter": "python", 398 | "pygments_lexer": "ipython3", 399 | "version": "3.8.3" 400 | } 401 | }, 402 | "nbformat": 4, 403 | "nbformat_minor": 4 404 | } 405 | -------------------------------------------------------------------------------- /day65-random-forest/heart.csv: -------------------------------------------------------------------------------- 1 | age,sex,cp,trestbps,chol,fbs,restecg,thalach,exang,oldpeak,slope,ca,thal,target 2 | 63,1,3,145,233,1,0,150,0,2.3,0,0,1,1 3 | 37,1,2,130,250,0,1,187,0,3.5,0,0,2,1 4 | 41,0,1,130,204,0,0,172,0,1.4,2,0,2,1 5 | 56,1,1,120,236,0,1,178,0,0.8,2,0,2,1 6 | 57,0,0,120,354,0,1,163,1,0.6,2,0,2,1 7 | 57,1,0,140,192,0,1,148,0,0.4,1,0,1,1 8 | 56,0,1,140,294,0,0,153,0,1.3,1,0,2,1 9 | 44,1,1,120,263,0,1,173,0,0,2,0,3,1 10 | 52,1,2,172,199,1,1,162,0,0.5,2,0,3,1 11 | 57,1,2,150,168,0,1,174,0,1.6,2,0,2,1 12 | 54,1,0,140,239,0,1,160,0,1.2,2,0,2,1 13 | 48,0,2,130,275,0,1,139,0,0.2,2,0,2,1 14 | 49,1,1,130,266,0,1,171,0,0.6,2,0,2,1 15 | 64,1,3,110,211,0,0,144,1,1.8,1,0,2,1 16 | 58,0,3,150,283,1,0,162,0,1,2,0,2,1 17 | 50,0,2,120,219,0,1,158,0,1.6,1,0,2,1 18 | 58,0,2,120,340,0,1,172,0,0,2,0,2,1 19 | 66,0,3,150,226,0,1,114,0,2.6,0,0,2,1 20 | 43,1,0,150,247,0,1,171,0,1.5,2,0,2,1 21 | 69,0,3,140,239,0,1,151,0,1.8,2,2,2,1 22 | 59,1,0,135,234,0,1,161,0,0.5,1,0,3,1 23 | 44,1,2,130,233,0,1,179,1,0.4,2,0,2,1 24 | 42,1,0,140,226,0,1,178,0,0,2,0,2,1 25 | 61,1,2,150,243,1,1,137,1,1,1,0,2,1 26 | 40,1,3,140,199,0,1,178,1,1.4,2,0,3,1 27 | 71,0,1,160,302,0,1,162,0,0.4,2,2,2,1 28 | 59,1,2,150,212,1,1,157,0,1.6,2,0,2,1 29 | 51,1,2,110,175,0,1,123,0,0.6,2,0,2,1 30 | 65,0,2,140,417,1,0,157,0,0.8,2,1,2,1 31 | 53,1,2,130,197,1,0,152,0,1.2,0,0,2,1 32 | 41,0,1,105,198,0,1,168,0,0,2,1,2,1 33 | 65,1,0,120,177,0,1,140,0,0.4,2,0,3,1 34 | 44,1,1,130,219,0,0,188,0,0,2,0,2,1 35 | 54,1,2,125,273,0,0,152,0,0.5,0,1,2,1 36 | 51,1,3,125,213,0,0,125,1,1.4,2,1,2,1 37 | 46,0,2,142,177,0,0,160,1,1.4,0,0,2,1 38 | 54,0,2,135,304,1,1,170,0,0,2,0,2,1 39 | 54,1,2,150,232,0,0,165,0,1.6,2,0,3,1 40 | 65,0,2,155,269,0,1,148,0,0.8,2,0,2,1 41 | 65,0,2,160,360,0,0,151,0,0.8,2,0,2,1 42 | 51,0,2,140,308,0,0,142,0,1.5,2,1,2,1 43 | 48,1,1,130,245,0,0,180,0,0.2,1,0,2,1 44 | 45,1,0,104,208,0,0,148,1,3,1,0,2,1 45 | 53,0,0,130,264,0,0,143,0,0.4,1,0,2,1 46 | 39,1,2,140,321,0,0,182,0,0,2,0,2,1 47 | 52,1,1,120,325,0,1,172,0,0.2,2,0,2,1 48 | 44,1,2,140,235,0,0,180,0,0,2,0,2,1 49 | 47,1,2,138,257,0,0,156,0,0,2,0,2,1 50 | 53,0,2,128,216,0,0,115,0,0,2,0,0,1 51 | 53,0,0,138,234,0,0,160,0,0,2,0,2,1 52 | 51,0,2,130,256,0,0,149,0,0.5,2,0,2,1 53 | 66,1,0,120,302,0,0,151,0,0.4,1,0,2,1 54 | 62,1,2,130,231,0,1,146,0,1.8,1,3,3,1 55 | 44,0,2,108,141,0,1,175,0,0.6,1,0,2,1 56 | 63,0,2,135,252,0,0,172,0,0,2,0,2,1 57 | 52,1,1,134,201,0,1,158,0,0.8,2,1,2,1 58 | 48,1,0,122,222,0,0,186,0,0,2,0,2,1 59 | 45,1,0,115,260,0,0,185,0,0,2,0,2,1 60 | 34,1,3,118,182,0,0,174,0,0,2,0,2,1 61 | 57,0,0,128,303,0,0,159,0,0,2,1,2,1 62 | 71,0,2,110,265,1,0,130,0,0,2,1,2,1 63 | 54,1,1,108,309,0,1,156,0,0,2,0,3,1 64 | 52,1,3,118,186,0,0,190,0,0,1,0,1,1 65 | 41,1,1,135,203,0,1,132,0,0,1,0,1,1 66 | 58,1,2,140,211,1,0,165,0,0,2,0,2,1 67 | 35,0,0,138,183,0,1,182,0,1.4,2,0,2,1 68 | 51,1,2,100,222,0,1,143,1,1.2,1,0,2,1 69 | 45,0,1,130,234,0,0,175,0,0.6,1,0,2,1 70 | 44,1,1,120,220,0,1,170,0,0,2,0,2,1 71 | 62,0,0,124,209,0,1,163,0,0,2,0,2,1 72 | 54,1,2,120,258,0,0,147,0,0.4,1,0,3,1 73 | 51,1,2,94,227,0,1,154,1,0,2,1,3,1 74 | 29,1,1,130,204,0,0,202,0,0,2,0,2,1 75 | 51,1,0,140,261,0,0,186,1,0,2,0,2,1 76 | 43,0,2,122,213,0,1,165,0,0.2,1,0,2,1 77 | 55,0,1,135,250,0,0,161,0,1.4,1,0,2,1 78 | 51,1,2,125,245,1,0,166,0,2.4,1,0,2,1 79 | 59,1,1,140,221,0,1,164,1,0,2,0,2,1 80 | 52,1,1,128,205,1,1,184,0,0,2,0,2,1 81 | 58,1,2,105,240,0,0,154,1,0.6,1,0,3,1 82 | 41,1,2,112,250,0,1,179,0,0,2,0,2,1 83 | 45,1,1,128,308,0,0,170,0,0,2,0,2,1 84 | 60,0,2,102,318,0,1,160,0,0,2,1,2,1 85 | 52,1,3,152,298,1,1,178,0,1.2,1,0,3,1 86 | 42,0,0,102,265,0,0,122,0,0.6,1,0,2,1 87 | 67,0,2,115,564,0,0,160,0,1.6,1,0,3,1 88 | 68,1,2,118,277,0,1,151,0,1,2,1,3,1 89 | 46,1,1,101,197,1,1,156,0,0,2,0,3,1 90 | 54,0,2,110,214,0,1,158,0,1.6,1,0,2,1 91 | 58,0,0,100,248,0,0,122,0,1,1,0,2,1 92 | 48,1,2,124,255,1,1,175,0,0,2,2,2,1 93 | 57,1,0,132,207,0,1,168,1,0,2,0,3,1 94 | 52,1,2,138,223,0,1,169,0,0,2,4,2,1 95 | 54,0,1,132,288,1,0,159,1,0,2,1,2,1 96 | 45,0,1,112,160,0,1,138,0,0,1,0,2,1 97 | 53,1,0,142,226,0,0,111,1,0,2,0,3,1 98 | 62,0,0,140,394,0,0,157,0,1.2,1,0,2,1 99 | 52,1,0,108,233,1,1,147,0,0.1,2,3,3,1 100 | 43,1,2,130,315,0,1,162,0,1.9,2,1,2,1 101 | 53,1,2,130,246,1,0,173,0,0,2,3,2,1 102 | 42,1,3,148,244,0,0,178,0,0.8,2,2,2,1 103 | 59,1,3,178,270,0,0,145,0,4.2,0,0,3,1 104 | 63,0,1,140,195,0,1,179,0,0,2,2,2,1 105 | 42,1,2,120,240,1,1,194,0,0.8,0,0,3,1 106 | 50,1,2,129,196,0,1,163,0,0,2,0,2,1 107 | 68,0,2,120,211,0,0,115,0,1.5,1,0,2,1 108 | 69,1,3,160,234,1,0,131,0,0.1,1,1,2,1 109 | 45,0,0,138,236,0,0,152,1,0.2,1,0,2,1 110 | 50,0,1,120,244,0,1,162,0,1.1,2,0,2,1 111 | 50,0,0,110,254,0,0,159,0,0,2,0,2,1 112 | 64,0,0,180,325,0,1,154,1,0,2,0,2,1 113 | 57,1,2,150,126,1,1,173,0,0.2,2,1,3,1 114 | 64,0,2,140,313,0,1,133,0,0.2,2,0,3,1 115 | 43,1,0,110,211,0,1,161,0,0,2,0,3,1 116 | 55,1,1,130,262,0,1,155,0,0,2,0,2,1 117 | 37,0,2,120,215,0,1,170,0,0,2,0,2,1 118 | 41,1,2,130,214,0,0,168,0,2,1,0,2,1 119 | 56,1,3,120,193,0,0,162,0,1.9,1,0,3,1 120 | 46,0,1,105,204,0,1,172,0,0,2,0,2,1 121 | 46,0,0,138,243,0,0,152,1,0,1,0,2,1 122 | 64,0,0,130,303,0,1,122,0,2,1,2,2,1 123 | 59,1,0,138,271,0,0,182,0,0,2,0,2,1 124 | 41,0,2,112,268,0,0,172,1,0,2,0,2,1 125 | 54,0,2,108,267,0,0,167,0,0,2,0,2,1 126 | 39,0,2,94,199,0,1,179,0,0,2,0,2,1 127 | 34,0,1,118,210,0,1,192,0,0.7,2,0,2,1 128 | 47,1,0,112,204,0,1,143,0,0.1,2,0,2,1 129 | 67,0,2,152,277,0,1,172,0,0,2,1,2,1 130 | 52,0,2,136,196,0,0,169,0,0.1,1,0,2,1 131 | 74,0,1,120,269,0,0,121,1,0.2,2,1,2,1 132 | 54,0,2,160,201,0,1,163,0,0,2,1,2,1 133 | 49,0,1,134,271,0,1,162,0,0,1,0,2,1 134 | 42,1,1,120,295,0,1,162,0,0,2,0,2,1 135 | 41,1,1,110,235,0,1,153,0,0,2,0,2,1 136 | 41,0,1,126,306,0,1,163,0,0,2,0,2,1 137 | 49,0,0,130,269,0,1,163,0,0,2,0,2,1 138 | 60,0,2,120,178,1,1,96,0,0,2,0,2,1 139 | 62,1,1,128,208,1,0,140,0,0,2,0,2,1 140 | 57,1,0,110,201,0,1,126,1,1.5,1,0,1,1 141 | 64,1,0,128,263,0,1,105,1,0.2,1,1,3,1 142 | 51,0,2,120,295,0,0,157,0,0.6,2,0,2,1 143 | 43,1,0,115,303,0,1,181,0,1.2,1,0,2,1 144 | 42,0,2,120,209,0,1,173,0,0,1,0,2,1 145 | 67,0,0,106,223,0,1,142,0,0.3,2,2,2,1 146 | 76,0,2,140,197,0,2,116,0,1.1,1,0,2,1 147 | 70,1,1,156,245,0,0,143,0,0,2,0,2,1 148 | 44,0,2,118,242,0,1,149,0,0.3,1,1,2,1 149 | 60,0,3,150,240,0,1,171,0,0.9,2,0,2,1 150 | 44,1,2,120,226,0,1,169,0,0,2,0,2,1 151 | 42,1,2,130,180,0,1,150,0,0,2,0,2,1 152 | 66,1,0,160,228,0,0,138,0,2.3,2,0,1,1 153 | 71,0,0,112,149,0,1,125,0,1.6,1,0,2,1 154 | 64,1,3,170,227,0,0,155,0,0.6,1,0,3,1 155 | 66,0,2,146,278,0,0,152,0,0,1,1,2,1 156 | 39,0,2,138,220,0,1,152,0,0,1,0,2,1 157 | 58,0,0,130,197,0,1,131,0,0.6,1,0,2,1 158 | 47,1,2,130,253,0,1,179,0,0,2,0,2,1 159 | 35,1,1,122,192,0,1,174,0,0,2,0,2,1 160 | 58,1,1,125,220,0,1,144,0,0.4,1,4,3,1 161 | 56,1,1,130,221,0,0,163,0,0,2,0,3,1 162 | 56,1,1,120,240,0,1,169,0,0,0,0,2,1 163 | 55,0,1,132,342,0,1,166,0,1.2,2,0,2,1 164 | 41,1,1,120,157,0,1,182,0,0,2,0,2,1 165 | 38,1,2,138,175,0,1,173,0,0,2,4,2,1 166 | 38,1,2,138,175,0,1,173,0,0,2,4,2,1 167 | 67,1,0,160,286,0,0,108,1,1.5,1,3,2,0 168 | 67,1,0,120,229,0,0,129,1,2.6,1,2,3,0 169 | 62,0,0,140,268,0,0,160,0,3.6,0,2,2,0 170 | 63,1,0,130,254,0,0,147,0,1.4,1,1,3,0 171 | 53,1,0,140,203,1,0,155,1,3.1,0,0,3,0 172 | 56,1,2,130,256,1,0,142,1,0.6,1,1,1,0 173 | 48,1,1,110,229,0,1,168,0,1,0,0,3,0 174 | 58,1,1,120,284,0,0,160,0,1.8,1,0,2,0 175 | 58,1,2,132,224,0,0,173,0,3.2,2,2,3,0 176 | 60,1,0,130,206,0,0,132,1,2.4,1,2,3,0 177 | 40,1,0,110,167,0,0,114,1,2,1,0,3,0 178 | 60,1,0,117,230,1,1,160,1,1.4,2,2,3,0 179 | 64,1,2,140,335,0,1,158,0,0,2,0,2,0 180 | 43,1,0,120,177,0,0,120,1,2.5,1,0,3,0 181 | 57,1,0,150,276,0,0,112,1,0.6,1,1,1,0 182 | 55,1,0,132,353,0,1,132,1,1.2,1,1,3,0 183 | 65,0,0,150,225,0,0,114,0,1,1,3,3,0 184 | 61,0,0,130,330,0,0,169,0,0,2,0,2,0 185 | 58,1,2,112,230,0,0,165,0,2.5,1,1,3,0 186 | 50,1,0,150,243,0,0,128,0,2.6,1,0,3,0 187 | 44,1,0,112,290,0,0,153,0,0,2,1,2,0 188 | 60,1,0,130,253,0,1,144,1,1.4,2,1,3,0 189 | 54,1,0,124,266,0,0,109,1,2.2,1,1,3,0 190 | 50,1,2,140,233,0,1,163,0,0.6,1,1,3,0 191 | 41,1,0,110,172,0,0,158,0,0,2,0,3,0 192 | 51,0,0,130,305,0,1,142,1,1.2,1,0,3,0 193 | 58,1,0,128,216,0,0,131,1,2.2,1,3,3,0 194 | 54,1,0,120,188,0,1,113,0,1.4,1,1,3,0 195 | 60,1,0,145,282,0,0,142,1,2.8,1,2,3,0 196 | 60,1,2,140,185,0,0,155,0,3,1,0,2,0 197 | 59,1,0,170,326,0,0,140,1,3.4,0,0,3,0 198 | 46,1,2,150,231,0,1,147,0,3.6,1,0,2,0 199 | 67,1,0,125,254,1,1,163,0,0.2,1,2,3,0 200 | 62,1,0,120,267,0,1,99,1,1.8,1,2,3,0 201 | 65,1,0,110,248,0,0,158,0,0.6,2,2,1,0 202 | 44,1,0,110,197,0,0,177,0,0,2,1,2,0 203 | 60,1,0,125,258,0,0,141,1,2.8,1,1,3,0 204 | 58,1,0,150,270,0,0,111,1,0.8,2,0,3,0 205 | 68,1,2,180,274,1,0,150,1,1.6,1,0,3,0 206 | 62,0,0,160,164,0,0,145,0,6.2,0,3,3,0 207 | 52,1,0,128,255,0,1,161,1,0,2,1,3,0 208 | 59,1,0,110,239,0,0,142,1,1.2,1,1,3,0 209 | 60,0,0,150,258,0,0,157,0,2.6,1,2,3,0 210 | 49,1,2,120,188,0,1,139,0,2,1,3,3,0 211 | 59,1,0,140,177,0,1,162,1,0,2,1,3,0 212 | 57,1,2,128,229,0,0,150,0,0.4,1,1,3,0 213 | 61,1,0,120,260,0,1,140,1,3.6,1,1,3,0 214 | 39,1,0,118,219,0,1,140,0,1.2,1,0,3,0 215 | 61,0,0,145,307,0,0,146,1,1,1,0,3,0 216 | 56,1,0,125,249,1,0,144,1,1.2,1,1,2,0 217 | 43,0,0,132,341,1,0,136,1,3,1,0,3,0 218 | 62,0,2,130,263,0,1,97,0,1.2,1,1,3,0 219 | 63,1,0,130,330,1,0,132,1,1.8,2,3,3,0 220 | 65,1,0,135,254,0,0,127,0,2.8,1,1,3,0 221 | 48,1,0,130,256,1,0,150,1,0,2,2,3,0 222 | 63,0,0,150,407,0,0,154,0,4,1,3,3,0 223 | 55,1,0,140,217,0,1,111,1,5.6,0,0,3,0 224 | 65,1,3,138,282,1,0,174,0,1.4,1,1,2,0 225 | 56,0,0,200,288,1,0,133,1,4,0,2,3,0 226 | 54,1,0,110,239,0,1,126,1,2.8,1,1,3,0 227 | 70,1,0,145,174,0,1,125,1,2.6,0,0,3,0 228 | 62,1,1,120,281,0,0,103,0,1.4,1,1,3,0 229 | 35,1,0,120,198,0,1,130,1,1.6,1,0,3,0 230 | 59,1,3,170,288,0,0,159,0,0.2,1,0,3,0 231 | 64,1,2,125,309,0,1,131,1,1.8,1,0,3,0 232 | 47,1,2,108,243,0,1,152,0,0,2,0,2,0 233 | 57,1,0,165,289,1,0,124,0,1,1,3,3,0 234 | 55,1,0,160,289,0,0,145,1,0.8,1,1,3,0 235 | 64,1,0,120,246,0,0,96,1,2.2,0,1,2,0 236 | 70,1,0,130,322,0,0,109,0,2.4,1,3,2,0 237 | 51,1,0,140,299,0,1,173,1,1.6,2,0,3,0 238 | 58,1,0,125,300,0,0,171,0,0,2,2,3,0 239 | 60,1,0,140,293,0,0,170,0,1.2,1,2,3,0 240 | 77,1,0,125,304,0,0,162,1,0,2,3,2,0 241 | 35,1,0,126,282,0,0,156,1,0,2,0,3,0 242 | 70,1,2,160,269,0,1,112,1,2.9,1,1,3,0 243 | 59,0,0,174,249,0,1,143,1,0,1,0,2,0 244 | 64,1,0,145,212,0,0,132,0,2,1,2,1,0 245 | 57,1,0,152,274,0,1,88,1,1.2,1,1,3,0 246 | 56,1,0,132,184,0,0,105,1,2.1,1,1,1,0 247 | 48,1,0,124,274,0,0,166,0,0.5,1,0,3,0 248 | 56,0,0,134,409,0,0,150,1,1.9,1,2,3,0 249 | 66,1,1,160,246,0,1,120,1,0,1,3,1,0 250 | 54,1,1,192,283,0,0,195,0,0,2,1,3,0 251 | 69,1,2,140,254,0,0,146,0,2,1,3,3,0 252 | 51,1,0,140,298,0,1,122,1,4.2,1,3,3,0 253 | 43,1,0,132,247,1,0,143,1,0.1,1,4,3,0 254 | 62,0,0,138,294,1,1,106,0,1.9,1,3,2,0 255 | 67,1,0,100,299,0,0,125,1,0.9,1,2,2,0 256 | 59,1,3,160,273,0,0,125,0,0,2,0,2,0 257 | 45,1,0,142,309,0,0,147,1,0,1,3,3,0 258 | 58,1,0,128,259,0,0,130,1,3,1,2,3,0 259 | 50,1,0,144,200,0,0,126,1,0.9,1,0,3,0 260 | 62,0,0,150,244,0,1,154,1,1.4,1,0,2,0 261 | 38,1,3,120,231,0,1,182,1,3.8,1,0,3,0 262 | 66,0,0,178,228,1,1,165,1,1,1,2,3,0 263 | 52,1,0,112,230,0,1,160,0,0,2,1,2,0 264 | 53,1,0,123,282,0,1,95,1,2,1,2,3,0 265 | 63,0,0,108,269,0,1,169,1,1.8,1,2,2,0 266 | 54,1,0,110,206,0,0,108,1,0,1,1,2,0 267 | 66,1,0,112,212,0,0,132,1,0.1,2,1,2,0 268 | 55,0,0,180,327,0,2,117,1,3.4,1,0,2,0 269 | 49,1,2,118,149,0,0,126,0,0.8,2,3,2,0 270 | 54,1,0,122,286,0,0,116,1,3.2,1,2,2,0 271 | 56,1,0,130,283,1,0,103,1,1.6,0,0,3,0 272 | 46,1,0,120,249,0,0,144,0,0.8,2,0,3,0 273 | 61,1,3,134,234,0,1,145,0,2.6,1,2,2,0 274 | 67,1,0,120,237,0,1,71,0,1,1,0,2,0 275 | 58,1,0,100,234,0,1,156,0,0.1,2,1,3,0 276 | 47,1,0,110,275,0,0,118,1,1,1,1,2,0 277 | 52,1,0,125,212,0,1,168,0,1,2,2,3,0 278 | 58,1,0,146,218,0,1,105,0,2,1,1,3,0 279 | 57,1,1,124,261,0,1,141,0,0.3,2,0,3,0 280 | 58,0,1,136,319,1,0,152,0,0,2,2,2,0 281 | 61,1,0,138,166,0,0,125,1,3.6,1,1,2,0 282 | 42,1,0,136,315,0,1,125,1,1.8,1,0,1,0 283 | 52,1,0,128,204,1,1,156,1,1,1,0,0,0 284 | 59,1,2,126,218,1,1,134,0,2.2,1,1,1,0 285 | 40,1,0,152,223,0,1,181,0,0,2,0,3,0 286 | 61,1,0,140,207,0,0,138,1,1.9,2,1,3,0 287 | 46,1,0,140,311,0,1,120,1,1.8,1,2,3,0 288 | 59,1,3,134,204,0,1,162,0,0.8,2,2,2,0 289 | 57,1,1,154,232,0,0,164,0,0,2,1,2,0 290 | 57,1,0,110,335,0,1,143,1,3,1,1,3,0 291 | 55,0,0,128,205,0,2,130,1,2,1,1,3,0 292 | 61,1,0,148,203,0,1,161,0,0,2,1,3,0 293 | 58,1,0,114,318,0,2,140,0,4.4,0,3,1,0 294 | 58,0,0,170,225,1,0,146,1,2.8,1,2,1,0 295 | 67,1,2,152,212,0,0,150,0,0.8,1,0,3,0 296 | 44,1,0,120,169,0,1,144,1,2.8,0,0,1,0 297 | 63,1,0,140,187,0,0,144,1,4,2,2,3,0 298 | 63,0,0,124,197,0,1,136,1,0,1,0,2,0 299 | 59,1,0,164,176,1,0,90,0,1,1,2,1,0 300 | 57,0,0,140,241,0,1,123,1,0.2,1,0,3,0 301 | 45,1,3,110,264,0,1,132,0,1.2,1,0,3,0 302 | 68,1,0,144,193,1,1,141,0,3.4,1,2,3,0 303 | 57,1,0,130,131,0,1,115,1,1.2,1,1,3,0 304 | 57,0,1,130,236,0,0,174,0,0,1,1,2,0 305 | -------------------------------------------------------------------------------- /day68-stacking-and-blending/heart.csv: -------------------------------------------------------------------------------- 1 | age,sex,cp,trestbps,chol,fbs,restecg,thalach,exang,oldpeak,slope,ca,thal,target 2 | 63,1,3,145,233,1,0,150,0,2.3,0,0,1,1 3 | 37,1,2,130,250,0,1,187,0,3.5,0,0,2,1 4 | 41,0,1,130,204,0,0,172,0,1.4,2,0,2,1 5 | 56,1,1,120,236,0,1,178,0,0.8,2,0,2,1 6 | 57,0,0,120,354,0,1,163,1,0.6,2,0,2,1 7 | 57,1,0,140,192,0,1,148,0,0.4,1,0,1,1 8 | 56,0,1,140,294,0,0,153,0,1.3,1,0,2,1 9 | 44,1,1,120,263,0,1,173,0,0,2,0,3,1 10 | 52,1,2,172,199,1,1,162,0,0.5,2,0,3,1 11 | 57,1,2,150,168,0,1,174,0,1.6,2,0,2,1 12 | 54,1,0,140,239,0,1,160,0,1.2,2,0,2,1 13 | 48,0,2,130,275,0,1,139,0,0.2,2,0,2,1 14 | 49,1,1,130,266,0,1,171,0,0.6,2,0,2,1 15 | 64,1,3,110,211,0,0,144,1,1.8,1,0,2,1 16 | 58,0,3,150,283,1,0,162,0,1,2,0,2,1 17 | 50,0,2,120,219,0,1,158,0,1.6,1,0,2,1 18 | 58,0,2,120,340,0,1,172,0,0,2,0,2,1 19 | 66,0,3,150,226,0,1,114,0,2.6,0,0,2,1 20 | 43,1,0,150,247,0,1,171,0,1.5,2,0,2,1 21 | 69,0,3,140,239,0,1,151,0,1.8,2,2,2,1 22 | 59,1,0,135,234,0,1,161,0,0.5,1,0,3,1 23 | 44,1,2,130,233,0,1,179,1,0.4,2,0,2,1 24 | 42,1,0,140,226,0,1,178,0,0,2,0,2,1 25 | 61,1,2,150,243,1,1,137,1,1,1,0,2,1 26 | 40,1,3,140,199,0,1,178,1,1.4,2,0,3,1 27 | 71,0,1,160,302,0,1,162,0,0.4,2,2,2,1 28 | 59,1,2,150,212,1,1,157,0,1.6,2,0,2,1 29 | 51,1,2,110,175,0,1,123,0,0.6,2,0,2,1 30 | 65,0,2,140,417,1,0,157,0,0.8,2,1,2,1 31 | 53,1,2,130,197,1,0,152,0,1.2,0,0,2,1 32 | 41,0,1,105,198,0,1,168,0,0,2,1,2,1 33 | 65,1,0,120,177,0,1,140,0,0.4,2,0,3,1 34 | 44,1,1,130,219,0,0,188,0,0,2,0,2,1 35 | 54,1,2,125,273,0,0,152,0,0.5,0,1,2,1 36 | 51,1,3,125,213,0,0,125,1,1.4,2,1,2,1 37 | 46,0,2,142,177,0,0,160,1,1.4,0,0,2,1 38 | 54,0,2,135,304,1,1,170,0,0,2,0,2,1 39 | 54,1,2,150,232,0,0,165,0,1.6,2,0,3,1 40 | 65,0,2,155,269,0,1,148,0,0.8,2,0,2,1 41 | 65,0,2,160,360,0,0,151,0,0.8,2,0,2,1 42 | 51,0,2,140,308,0,0,142,0,1.5,2,1,2,1 43 | 48,1,1,130,245,0,0,180,0,0.2,1,0,2,1 44 | 45,1,0,104,208,0,0,148,1,3,1,0,2,1 45 | 53,0,0,130,264,0,0,143,0,0.4,1,0,2,1 46 | 39,1,2,140,321,0,0,182,0,0,2,0,2,1 47 | 52,1,1,120,325,0,1,172,0,0.2,2,0,2,1 48 | 44,1,2,140,235,0,0,180,0,0,2,0,2,1 49 | 47,1,2,138,257,0,0,156,0,0,2,0,2,1 50 | 53,0,2,128,216,0,0,115,0,0,2,0,0,1 51 | 53,0,0,138,234,0,0,160,0,0,2,0,2,1 52 | 51,0,2,130,256,0,0,149,0,0.5,2,0,2,1 53 | 66,1,0,120,302,0,0,151,0,0.4,1,0,2,1 54 | 62,1,2,130,231,0,1,146,0,1.8,1,3,3,1 55 | 44,0,2,108,141,0,1,175,0,0.6,1,0,2,1 56 | 63,0,2,135,252,0,0,172,0,0,2,0,2,1 57 | 52,1,1,134,201,0,1,158,0,0.8,2,1,2,1 58 | 48,1,0,122,222,0,0,186,0,0,2,0,2,1 59 | 45,1,0,115,260,0,0,185,0,0,2,0,2,1 60 | 34,1,3,118,182,0,0,174,0,0,2,0,2,1 61 | 57,0,0,128,303,0,0,159,0,0,2,1,2,1 62 | 71,0,2,110,265,1,0,130,0,0,2,1,2,1 63 | 54,1,1,108,309,0,1,156,0,0,2,0,3,1 64 | 52,1,3,118,186,0,0,190,0,0,1,0,1,1 65 | 41,1,1,135,203,0,1,132,0,0,1,0,1,1 66 | 58,1,2,140,211,1,0,165,0,0,2,0,2,1 67 | 35,0,0,138,183,0,1,182,0,1.4,2,0,2,1 68 | 51,1,2,100,222,0,1,143,1,1.2,1,0,2,1 69 | 45,0,1,130,234,0,0,175,0,0.6,1,0,2,1 70 | 44,1,1,120,220,0,1,170,0,0,2,0,2,1 71 | 62,0,0,124,209,0,1,163,0,0,2,0,2,1 72 | 54,1,2,120,258,0,0,147,0,0.4,1,0,3,1 73 | 51,1,2,94,227,0,1,154,1,0,2,1,3,1 74 | 29,1,1,130,204,0,0,202,0,0,2,0,2,1 75 | 51,1,0,140,261,0,0,186,1,0,2,0,2,1 76 | 43,0,2,122,213,0,1,165,0,0.2,1,0,2,1 77 | 55,0,1,135,250,0,0,161,0,1.4,1,0,2,1 78 | 51,1,2,125,245,1,0,166,0,2.4,1,0,2,1 79 | 59,1,1,140,221,0,1,164,1,0,2,0,2,1 80 | 52,1,1,128,205,1,1,184,0,0,2,0,2,1 81 | 58,1,2,105,240,0,0,154,1,0.6,1,0,3,1 82 | 41,1,2,112,250,0,1,179,0,0,2,0,2,1 83 | 45,1,1,128,308,0,0,170,0,0,2,0,2,1 84 | 60,0,2,102,318,0,1,160,0,0,2,1,2,1 85 | 52,1,3,152,298,1,1,178,0,1.2,1,0,3,1 86 | 42,0,0,102,265,0,0,122,0,0.6,1,0,2,1 87 | 67,0,2,115,564,0,0,160,0,1.6,1,0,3,1 88 | 68,1,2,118,277,0,1,151,0,1,2,1,3,1 89 | 46,1,1,101,197,1,1,156,0,0,2,0,3,1 90 | 54,0,2,110,214,0,1,158,0,1.6,1,0,2,1 91 | 58,0,0,100,248,0,0,122,0,1,1,0,2,1 92 | 48,1,2,124,255,1,1,175,0,0,2,2,2,1 93 | 57,1,0,132,207,0,1,168,1,0,2,0,3,1 94 | 52,1,2,138,223,0,1,169,0,0,2,4,2,1 95 | 54,0,1,132,288,1,0,159,1,0,2,1,2,1 96 | 45,0,1,112,160,0,1,138,0,0,1,0,2,1 97 | 53,1,0,142,226,0,0,111,1,0,2,0,3,1 98 | 62,0,0,140,394,0,0,157,0,1.2,1,0,2,1 99 | 52,1,0,108,233,1,1,147,0,0.1,2,3,3,1 100 | 43,1,2,130,315,0,1,162,0,1.9,2,1,2,1 101 | 53,1,2,130,246,1,0,173,0,0,2,3,2,1 102 | 42,1,3,148,244,0,0,178,0,0.8,2,2,2,1 103 | 59,1,3,178,270,0,0,145,0,4.2,0,0,3,1 104 | 63,0,1,140,195,0,1,179,0,0,2,2,2,1 105 | 42,1,2,120,240,1,1,194,0,0.8,0,0,3,1 106 | 50,1,2,129,196,0,1,163,0,0,2,0,2,1 107 | 68,0,2,120,211,0,0,115,0,1.5,1,0,2,1 108 | 69,1,3,160,234,1,0,131,0,0.1,1,1,2,1 109 | 45,0,0,138,236,0,0,152,1,0.2,1,0,2,1 110 | 50,0,1,120,244,0,1,162,0,1.1,2,0,2,1 111 | 50,0,0,110,254,0,0,159,0,0,2,0,2,1 112 | 64,0,0,180,325,0,1,154,1,0,2,0,2,1 113 | 57,1,2,150,126,1,1,173,0,0.2,2,1,3,1 114 | 64,0,2,140,313,0,1,133,0,0.2,2,0,3,1 115 | 43,1,0,110,211,0,1,161,0,0,2,0,3,1 116 | 55,1,1,130,262,0,1,155,0,0,2,0,2,1 117 | 37,0,2,120,215,0,1,170,0,0,2,0,2,1 118 | 41,1,2,130,214,0,0,168,0,2,1,0,2,1 119 | 56,1,3,120,193,0,0,162,0,1.9,1,0,3,1 120 | 46,0,1,105,204,0,1,172,0,0,2,0,2,1 121 | 46,0,0,138,243,0,0,152,1,0,1,0,2,1 122 | 64,0,0,130,303,0,1,122,0,2,1,2,2,1 123 | 59,1,0,138,271,0,0,182,0,0,2,0,2,1 124 | 41,0,2,112,268,0,0,172,1,0,2,0,2,1 125 | 54,0,2,108,267,0,0,167,0,0,2,0,2,1 126 | 39,0,2,94,199,0,1,179,0,0,2,0,2,1 127 | 34,0,1,118,210,0,1,192,0,0.7,2,0,2,1 128 | 47,1,0,112,204,0,1,143,0,0.1,2,0,2,1 129 | 67,0,2,152,277,0,1,172,0,0,2,1,2,1 130 | 52,0,2,136,196,0,0,169,0,0.1,1,0,2,1 131 | 74,0,1,120,269,0,0,121,1,0.2,2,1,2,1 132 | 54,0,2,160,201,0,1,163,0,0,2,1,2,1 133 | 49,0,1,134,271,0,1,162,0,0,1,0,2,1 134 | 42,1,1,120,295,0,1,162,0,0,2,0,2,1 135 | 41,1,1,110,235,0,1,153,0,0,2,0,2,1 136 | 41,0,1,126,306,0,1,163,0,0,2,0,2,1 137 | 49,0,0,130,269,0,1,163,0,0,2,0,2,1 138 | 60,0,2,120,178,1,1,96,0,0,2,0,2,1 139 | 62,1,1,128,208,1,0,140,0,0,2,0,2,1 140 | 57,1,0,110,201,0,1,126,1,1.5,1,0,1,1 141 | 64,1,0,128,263,0,1,105,1,0.2,1,1,3,1 142 | 51,0,2,120,295,0,0,157,0,0.6,2,0,2,1 143 | 43,1,0,115,303,0,1,181,0,1.2,1,0,2,1 144 | 42,0,2,120,209,0,1,173,0,0,1,0,2,1 145 | 67,0,0,106,223,0,1,142,0,0.3,2,2,2,1 146 | 76,0,2,140,197,0,2,116,0,1.1,1,0,2,1 147 | 70,1,1,156,245,0,0,143,0,0,2,0,2,1 148 | 44,0,2,118,242,0,1,149,0,0.3,1,1,2,1 149 | 60,0,3,150,240,0,1,171,0,0.9,2,0,2,1 150 | 44,1,2,120,226,0,1,169,0,0,2,0,2,1 151 | 42,1,2,130,180,0,1,150,0,0,2,0,2,1 152 | 66,1,0,160,228,0,0,138,0,2.3,2,0,1,1 153 | 71,0,0,112,149,0,1,125,0,1.6,1,0,2,1 154 | 64,1,3,170,227,0,0,155,0,0.6,1,0,3,1 155 | 66,0,2,146,278,0,0,152,0,0,1,1,2,1 156 | 39,0,2,138,220,0,1,152,0,0,1,0,2,1 157 | 58,0,0,130,197,0,1,131,0,0.6,1,0,2,1 158 | 47,1,2,130,253,0,1,179,0,0,2,0,2,1 159 | 35,1,1,122,192,0,1,174,0,0,2,0,2,1 160 | 58,1,1,125,220,0,1,144,0,0.4,1,4,3,1 161 | 56,1,1,130,221,0,0,163,0,0,2,0,3,1 162 | 56,1,1,120,240,0,1,169,0,0,0,0,2,1 163 | 55,0,1,132,342,0,1,166,0,1.2,2,0,2,1 164 | 41,1,1,120,157,0,1,182,0,0,2,0,2,1 165 | 38,1,2,138,175,0,1,173,0,0,2,4,2,1 166 | 38,1,2,138,175,0,1,173,0,0,2,4,2,1 167 | 67,1,0,160,286,0,0,108,1,1.5,1,3,2,0 168 | 67,1,0,120,229,0,0,129,1,2.6,1,2,3,0 169 | 62,0,0,140,268,0,0,160,0,3.6,0,2,2,0 170 | 63,1,0,130,254,0,0,147,0,1.4,1,1,3,0 171 | 53,1,0,140,203,1,0,155,1,3.1,0,0,3,0 172 | 56,1,2,130,256,1,0,142,1,0.6,1,1,1,0 173 | 48,1,1,110,229,0,1,168,0,1,0,0,3,0 174 | 58,1,1,120,284,0,0,160,0,1.8,1,0,2,0 175 | 58,1,2,132,224,0,0,173,0,3.2,2,2,3,0 176 | 60,1,0,130,206,0,0,132,1,2.4,1,2,3,0 177 | 40,1,0,110,167,0,0,114,1,2,1,0,3,0 178 | 60,1,0,117,230,1,1,160,1,1.4,2,2,3,0 179 | 64,1,2,140,335,0,1,158,0,0,2,0,2,0 180 | 43,1,0,120,177,0,0,120,1,2.5,1,0,3,0 181 | 57,1,0,150,276,0,0,112,1,0.6,1,1,1,0 182 | 55,1,0,132,353,0,1,132,1,1.2,1,1,3,0 183 | 65,0,0,150,225,0,0,114,0,1,1,3,3,0 184 | 61,0,0,130,330,0,0,169,0,0,2,0,2,0 185 | 58,1,2,112,230,0,0,165,0,2.5,1,1,3,0 186 | 50,1,0,150,243,0,0,128,0,2.6,1,0,3,0 187 | 44,1,0,112,290,0,0,153,0,0,2,1,2,0 188 | 60,1,0,130,253,0,1,144,1,1.4,2,1,3,0 189 | 54,1,0,124,266,0,0,109,1,2.2,1,1,3,0 190 | 50,1,2,140,233,0,1,163,0,0.6,1,1,3,0 191 | 41,1,0,110,172,0,0,158,0,0,2,0,3,0 192 | 51,0,0,130,305,0,1,142,1,1.2,1,0,3,0 193 | 58,1,0,128,216,0,0,131,1,2.2,1,3,3,0 194 | 54,1,0,120,188,0,1,113,0,1.4,1,1,3,0 195 | 60,1,0,145,282,0,0,142,1,2.8,1,2,3,0 196 | 60,1,2,140,185,0,0,155,0,3,1,0,2,0 197 | 59,1,0,170,326,0,0,140,1,3.4,0,0,3,0 198 | 46,1,2,150,231,0,1,147,0,3.6,1,0,2,0 199 | 67,1,0,125,254,1,1,163,0,0.2,1,2,3,0 200 | 62,1,0,120,267,0,1,99,1,1.8,1,2,3,0 201 | 65,1,0,110,248,0,0,158,0,0.6,2,2,1,0 202 | 44,1,0,110,197,0,0,177,0,0,2,1,2,0 203 | 60,1,0,125,258,0,0,141,1,2.8,1,1,3,0 204 | 58,1,0,150,270,0,0,111,1,0.8,2,0,3,0 205 | 68,1,2,180,274,1,0,150,1,1.6,1,0,3,0 206 | 62,0,0,160,164,0,0,145,0,6.2,0,3,3,0 207 | 52,1,0,128,255,0,1,161,1,0,2,1,3,0 208 | 59,1,0,110,239,0,0,142,1,1.2,1,1,3,0 209 | 60,0,0,150,258,0,0,157,0,2.6,1,2,3,0 210 | 49,1,2,120,188,0,1,139,0,2,1,3,3,0 211 | 59,1,0,140,177,0,1,162,1,0,2,1,3,0 212 | 57,1,2,128,229,0,0,150,0,0.4,1,1,3,0 213 | 61,1,0,120,260,0,1,140,1,3.6,1,1,3,0 214 | 39,1,0,118,219,0,1,140,0,1.2,1,0,3,0 215 | 61,0,0,145,307,0,0,146,1,1,1,0,3,0 216 | 56,1,0,125,249,1,0,144,1,1.2,1,1,2,0 217 | 43,0,0,132,341,1,0,136,1,3,1,0,3,0 218 | 62,0,2,130,263,0,1,97,0,1.2,1,1,3,0 219 | 63,1,0,130,330,1,0,132,1,1.8,2,3,3,0 220 | 65,1,0,135,254,0,0,127,0,2.8,1,1,3,0 221 | 48,1,0,130,256,1,0,150,1,0,2,2,3,0 222 | 63,0,0,150,407,0,0,154,0,4,1,3,3,0 223 | 55,1,0,140,217,0,1,111,1,5.6,0,0,3,0 224 | 65,1,3,138,282,1,0,174,0,1.4,1,1,2,0 225 | 56,0,0,200,288,1,0,133,1,4,0,2,3,0 226 | 54,1,0,110,239,0,1,126,1,2.8,1,1,3,0 227 | 70,1,0,145,174,0,1,125,1,2.6,0,0,3,0 228 | 62,1,1,120,281,0,0,103,0,1.4,1,1,3,0 229 | 35,1,0,120,198,0,1,130,1,1.6,1,0,3,0 230 | 59,1,3,170,288,0,0,159,0,0.2,1,0,3,0 231 | 64,1,2,125,309,0,1,131,1,1.8,1,0,3,0 232 | 47,1,2,108,243,0,1,152,0,0,2,0,2,0 233 | 57,1,0,165,289,1,0,124,0,1,1,3,3,0 234 | 55,1,0,160,289,0,0,145,1,0.8,1,1,3,0 235 | 64,1,0,120,246,0,0,96,1,2.2,0,1,2,0 236 | 70,1,0,130,322,0,0,109,0,2.4,1,3,2,0 237 | 51,1,0,140,299,0,1,173,1,1.6,2,0,3,0 238 | 58,1,0,125,300,0,0,171,0,0,2,2,3,0 239 | 60,1,0,140,293,0,0,170,0,1.2,1,2,3,0 240 | 77,1,0,125,304,0,0,162,1,0,2,3,2,0 241 | 35,1,0,126,282,0,0,156,1,0,2,0,3,0 242 | 70,1,2,160,269,0,1,112,1,2.9,1,1,3,0 243 | 59,0,0,174,249,0,1,143,1,0,1,0,2,0 244 | 64,1,0,145,212,0,0,132,0,2,1,2,1,0 245 | 57,1,0,152,274,0,1,88,1,1.2,1,1,3,0 246 | 56,1,0,132,184,0,0,105,1,2.1,1,1,1,0 247 | 48,1,0,124,274,0,0,166,0,0.5,1,0,3,0 248 | 56,0,0,134,409,0,0,150,1,1.9,1,2,3,0 249 | 66,1,1,160,246,0,1,120,1,0,1,3,1,0 250 | 54,1,1,192,283,0,0,195,0,0,2,1,3,0 251 | 69,1,2,140,254,0,0,146,0,2,1,3,3,0 252 | 51,1,0,140,298,0,1,122,1,4.2,1,3,3,0 253 | 43,1,0,132,247,1,0,143,1,0.1,1,4,3,0 254 | 62,0,0,138,294,1,1,106,0,1.9,1,3,2,0 255 | 67,1,0,100,299,0,0,125,1,0.9,1,2,2,0 256 | 59,1,3,160,273,0,0,125,0,0,2,0,2,0 257 | 45,1,0,142,309,0,0,147,1,0,1,3,3,0 258 | 58,1,0,128,259,0,0,130,1,3,1,2,3,0 259 | 50,1,0,144,200,0,0,126,1,0.9,1,0,3,0 260 | 62,0,0,150,244,0,1,154,1,1.4,1,0,2,0 261 | 38,1,3,120,231,0,1,182,1,3.8,1,0,3,0 262 | 66,0,0,178,228,1,1,165,1,1,1,2,3,0 263 | 52,1,0,112,230,0,1,160,0,0,2,1,2,0 264 | 53,1,0,123,282,0,1,95,1,2,1,2,3,0 265 | 63,0,0,108,269,0,1,169,1,1.8,1,2,2,0 266 | 54,1,0,110,206,0,0,108,1,0,1,1,2,0 267 | 66,1,0,112,212,0,0,132,1,0.1,2,1,2,0 268 | 55,0,0,180,327,0,2,117,1,3.4,1,0,2,0 269 | 49,1,2,118,149,0,0,126,0,0.8,2,3,2,0 270 | 54,1,0,122,286,0,0,116,1,3.2,1,2,2,0 271 | 56,1,0,130,283,1,0,103,1,1.6,0,0,3,0 272 | 46,1,0,120,249,0,0,144,0,0.8,2,0,3,0 273 | 61,1,3,134,234,0,1,145,0,2.6,1,2,2,0 274 | 67,1,0,120,237,0,1,71,0,1,1,0,2,0 275 | 58,1,0,100,234,0,1,156,0,0.1,2,1,3,0 276 | 47,1,0,110,275,0,0,118,1,1,1,1,2,0 277 | 52,1,0,125,212,0,1,168,0,1,2,2,3,0 278 | 58,1,0,146,218,0,1,105,0,2,1,1,3,0 279 | 57,1,1,124,261,0,1,141,0,0.3,2,0,3,0 280 | 58,0,1,136,319,1,0,152,0,0,2,2,2,0 281 | 61,1,0,138,166,0,0,125,1,3.6,1,1,2,0 282 | 42,1,0,136,315,0,1,125,1,1.8,1,0,1,0 283 | 52,1,0,128,204,1,1,156,1,1,1,0,0,0 284 | 59,1,2,126,218,1,1,134,0,2.2,1,1,1,0 285 | 40,1,0,152,223,0,1,181,0,0,2,0,3,0 286 | 61,1,0,140,207,0,0,138,1,1.9,2,1,3,0 287 | 46,1,0,140,311,0,1,120,1,1.8,1,2,3,0 288 | 59,1,3,134,204,0,1,162,0,0.8,2,2,2,0 289 | 57,1,1,154,232,0,0,164,0,0,2,1,2,0 290 | 57,1,0,110,335,0,1,143,1,3,1,1,3,0 291 | 55,0,0,128,205,0,2,130,1,2,1,1,3,0 292 | 61,1,0,148,203,0,1,161,0,0,2,1,3,0 293 | 58,1,0,114,318,0,2,140,0,4.4,0,3,1,0 294 | 58,0,0,170,225,1,0,146,1,2.8,1,2,1,0 295 | 67,1,2,152,212,0,0,150,0,0.8,1,0,3,0 296 | 44,1,0,120,169,0,1,144,1,2.8,0,0,1,0 297 | 63,1,0,140,187,0,0,144,1,4,2,2,3,0 298 | 63,0,0,124,197,0,1,136,1,0,1,0,2,0 299 | 59,1,0,164,176,1,0,90,0,1,1,2,1,0 300 | 57,0,0,140,241,0,1,123,1,0.2,1,0,3,0 301 | 45,1,3,110,264,0,1,132,0,1.2,1,0,3,0 302 | 68,1,0,144,193,1,1,141,0,3.4,1,2,3,0 303 | 57,1,0,130,131,0,1,115,1,1.2,1,1,3,0 304 | 57,0,1,130,236,0,0,174,0,0,1,1,2,0 305 | -------------------------------------------------------------------------------- /day24-standardization/Social_Network_Ads.csv: -------------------------------------------------------------------------------- 1 | User ID,Gender,Age,EstimatedSalary,Purchased 2 | 15624510,Male,19,19000,0 3 | 15810944,Male,35,20000,0 4 | 15668575,Female,26,43000,0 5 | 15603246,Female,27,57000,0 6 | 15804002,Male,19,76000,0 7 | 15728773,Male,27,58000,0 8 | 15598044,Female,27,84000,0 9 | 15694829,Female,32,150000,1 10 | 15600575,Male,25,33000,0 11 | 15727311,Female,35,65000,0 12 | 15570769,Female,26,80000,0 13 | 15606274,Female,26,52000,0 14 | 15746139,Male,20,86000,0 15 | 15704987,Male,32,18000,0 16 | 15628972,Male,18,82000,0 17 | 15697686,Male,29,80000,0 18 | 15733883,Male,47,25000,1 19 | 15617482,Male,45,26000,1 20 | 15704583,Male,46,28000,1 21 | 15621083,Female,48,29000,1 22 | 15649487,Male,45,22000,1 23 | 15736760,Female,47,49000,1 24 | 15714658,Male,48,41000,1 25 | 15599081,Female,45,22000,1 26 | 15705113,Male,46,23000,1 27 | 15631159,Male,47,20000,1 28 | 15792818,Male,49,28000,1 29 | 15633531,Female,47,30000,1 30 | 15744529,Male,29,43000,0 31 | 15669656,Male,31,18000,0 32 | 15581198,Male,31,74000,0 33 | 15729054,Female,27,137000,1 34 | 15573452,Female,21,16000,0 35 | 15776733,Female,28,44000,0 36 | 15724858,Male,27,90000,0 37 | 15713144,Male,35,27000,0 38 | 15690188,Female,33,28000,0 39 | 15689425,Male,30,49000,0 40 | 15671766,Female,26,72000,0 41 | 15782806,Female,27,31000,0 42 | 15764419,Female,27,17000,0 43 | 15591915,Female,33,51000,0 44 | 15772798,Male,35,108000,0 45 | 15792008,Male,30,15000,0 46 | 15715541,Female,28,84000,0 47 | 15639277,Male,23,20000,0 48 | 15798850,Male,25,79000,0 49 | 15776348,Female,27,54000,0 50 | 15727696,Male,30,135000,1 51 | 15793813,Female,31,89000,0 52 | 15694395,Female,24,32000,0 53 | 15764195,Female,18,44000,0 54 | 15744919,Female,29,83000,0 55 | 15671655,Female,35,23000,0 56 | 15654901,Female,27,58000,0 57 | 15649136,Female,24,55000,0 58 | 15775562,Female,23,48000,0 59 | 15807481,Male,28,79000,0 60 | 15642885,Male,22,18000,0 61 | 15789109,Female,32,117000,0 62 | 15814004,Male,27,20000,0 63 | 15673619,Male,25,87000,0 64 | 15595135,Female,23,66000,0 65 | 15583681,Male,32,120000,1 66 | 15605000,Female,59,83000,0 67 | 15718071,Male,24,58000,0 68 | 15679760,Male,24,19000,0 69 | 15654574,Female,23,82000,0 70 | 15577178,Female,22,63000,0 71 | 15595324,Female,31,68000,0 72 | 15756932,Male,25,80000,0 73 | 15726358,Female,24,27000,0 74 | 15595228,Female,20,23000,0 75 | 15782530,Female,33,113000,0 76 | 15592877,Male,32,18000,0 77 | 15651983,Male,34,112000,1 78 | 15746737,Male,18,52000,0 79 | 15774179,Female,22,27000,0 80 | 15667265,Female,28,87000,0 81 | 15655123,Female,26,17000,0 82 | 15595917,Male,30,80000,0 83 | 15668385,Male,39,42000,0 84 | 15709476,Male,20,49000,0 85 | 15711218,Male,35,88000,0 86 | 15798659,Female,30,62000,0 87 | 15663939,Female,31,118000,1 88 | 15694946,Male,24,55000,0 89 | 15631912,Female,28,85000,0 90 | 15768816,Male,26,81000,0 91 | 15682268,Male,35,50000,0 92 | 15684801,Male,22,81000,0 93 | 15636428,Female,30,116000,0 94 | 15809823,Male,26,15000,0 95 | 15699284,Female,29,28000,0 96 | 15786993,Female,29,83000,0 97 | 15709441,Female,35,44000,0 98 | 15710257,Female,35,25000,0 99 | 15582492,Male,28,123000,1 100 | 15575694,Male,35,73000,0 101 | 15756820,Female,28,37000,0 102 | 15766289,Male,27,88000,0 103 | 15593014,Male,28,59000,0 104 | 15584545,Female,32,86000,0 105 | 15675949,Female,33,149000,1 106 | 15672091,Female,19,21000,0 107 | 15801658,Male,21,72000,0 108 | 15706185,Female,26,35000,0 109 | 15789863,Male,27,89000,0 110 | 15720943,Male,26,86000,0 111 | 15697997,Female,38,80000,0 112 | 15665416,Female,39,71000,0 113 | 15660200,Female,37,71000,0 114 | 15619653,Male,38,61000,0 115 | 15773447,Male,37,55000,0 116 | 15739160,Male,42,80000,0 117 | 15689237,Male,40,57000,0 118 | 15679297,Male,35,75000,0 119 | 15591433,Male,36,52000,0 120 | 15642725,Male,40,59000,0 121 | 15701962,Male,41,59000,0 122 | 15811613,Female,36,75000,0 123 | 15741049,Male,37,72000,0 124 | 15724423,Female,40,75000,0 125 | 15574305,Male,35,53000,0 126 | 15678168,Female,41,51000,0 127 | 15697020,Female,39,61000,0 128 | 15610801,Male,42,65000,0 129 | 15745232,Male,26,32000,0 130 | 15722758,Male,30,17000,0 131 | 15792102,Female,26,84000,0 132 | 15675185,Male,31,58000,0 133 | 15801247,Male,33,31000,0 134 | 15725660,Male,30,87000,0 135 | 15638963,Female,21,68000,0 136 | 15800061,Female,28,55000,0 137 | 15578006,Male,23,63000,0 138 | 15668504,Female,20,82000,0 139 | 15687491,Male,30,107000,1 140 | 15610403,Female,28,59000,0 141 | 15741094,Male,19,25000,0 142 | 15807909,Male,19,85000,0 143 | 15666141,Female,18,68000,0 144 | 15617134,Male,35,59000,0 145 | 15783029,Male,30,89000,0 146 | 15622833,Female,34,25000,0 147 | 15746422,Female,24,89000,0 148 | 15750839,Female,27,96000,1 149 | 15749130,Female,41,30000,0 150 | 15779862,Male,29,61000,0 151 | 15767871,Male,20,74000,0 152 | 15679651,Female,26,15000,0 153 | 15576219,Male,41,45000,0 154 | 15699247,Male,31,76000,0 155 | 15619087,Female,36,50000,0 156 | 15605327,Male,40,47000,0 157 | 15610140,Female,31,15000,0 158 | 15791174,Male,46,59000,0 159 | 15602373,Male,29,75000,0 160 | 15762605,Male,26,30000,0 161 | 15598840,Female,32,135000,1 162 | 15744279,Male,32,100000,1 163 | 15670619,Male,25,90000,0 164 | 15599533,Female,37,33000,0 165 | 15757837,Male,35,38000,0 166 | 15697574,Female,33,69000,0 167 | 15578738,Female,18,86000,0 168 | 15762228,Female,22,55000,0 169 | 15614827,Female,35,71000,0 170 | 15789815,Male,29,148000,1 171 | 15579781,Female,29,47000,0 172 | 15587013,Male,21,88000,0 173 | 15570932,Male,34,115000,0 174 | 15794661,Female,26,118000,0 175 | 15581654,Female,34,43000,0 176 | 15644296,Female,34,72000,0 177 | 15614420,Female,23,28000,0 178 | 15609653,Female,35,47000,0 179 | 15594577,Male,25,22000,0 180 | 15584114,Male,24,23000,0 181 | 15673367,Female,31,34000,0 182 | 15685576,Male,26,16000,0 183 | 15774727,Female,31,71000,0 184 | 15694288,Female,32,117000,1 185 | 15603319,Male,33,43000,0 186 | 15759066,Female,33,60000,0 187 | 15814816,Male,31,66000,0 188 | 15724402,Female,20,82000,0 189 | 15571059,Female,33,41000,0 190 | 15674206,Male,35,72000,0 191 | 15715160,Male,28,32000,0 192 | 15730448,Male,24,84000,0 193 | 15662067,Female,19,26000,0 194 | 15779581,Male,29,43000,0 195 | 15662901,Male,19,70000,0 196 | 15689751,Male,28,89000,0 197 | 15667742,Male,34,43000,0 198 | 15738448,Female,30,79000,0 199 | 15680243,Female,20,36000,0 200 | 15745083,Male,26,80000,0 201 | 15708228,Male,35,22000,0 202 | 15628523,Male,35,39000,0 203 | 15708196,Male,49,74000,0 204 | 15735549,Female,39,134000,1 205 | 15809347,Female,41,71000,0 206 | 15660866,Female,58,101000,1 207 | 15766609,Female,47,47000,0 208 | 15654230,Female,55,130000,1 209 | 15794566,Female,52,114000,0 210 | 15800890,Female,40,142000,1 211 | 15697424,Female,46,22000,0 212 | 15724536,Female,48,96000,1 213 | 15735878,Male,52,150000,1 214 | 15707596,Female,59,42000,0 215 | 15657163,Male,35,58000,0 216 | 15622478,Male,47,43000,0 217 | 15779529,Female,60,108000,1 218 | 15636023,Male,49,65000,0 219 | 15582066,Male,40,78000,0 220 | 15666675,Female,46,96000,0 221 | 15732987,Male,59,143000,1 222 | 15789432,Female,41,80000,0 223 | 15663161,Male,35,91000,1 224 | 15694879,Male,37,144000,1 225 | 15593715,Male,60,102000,1 226 | 15575002,Female,35,60000,0 227 | 15622171,Male,37,53000,0 228 | 15795224,Female,36,126000,1 229 | 15685346,Male,56,133000,1 230 | 15691808,Female,40,72000,0 231 | 15721007,Female,42,80000,1 232 | 15794253,Female,35,147000,1 233 | 15694453,Male,39,42000,0 234 | 15813113,Male,40,107000,1 235 | 15614187,Male,49,86000,1 236 | 15619407,Female,38,112000,0 237 | 15646227,Male,46,79000,1 238 | 15660541,Male,40,57000,0 239 | 15753874,Female,37,80000,0 240 | 15617877,Female,46,82000,0 241 | 15772073,Female,53,143000,1 242 | 15701537,Male,42,149000,1 243 | 15736228,Male,38,59000,0 244 | 15780572,Female,50,88000,1 245 | 15769596,Female,56,104000,1 246 | 15586996,Female,41,72000,0 247 | 15722061,Female,51,146000,1 248 | 15638003,Female,35,50000,0 249 | 15775590,Female,57,122000,1 250 | 15730688,Male,41,52000,0 251 | 15753102,Female,35,97000,1 252 | 15810075,Female,44,39000,0 253 | 15723373,Male,37,52000,0 254 | 15795298,Female,48,134000,1 255 | 15584320,Female,37,146000,1 256 | 15724161,Female,50,44000,0 257 | 15750056,Female,52,90000,1 258 | 15609637,Female,41,72000,0 259 | 15794493,Male,40,57000,0 260 | 15569641,Female,58,95000,1 261 | 15815236,Female,45,131000,1 262 | 15811177,Female,35,77000,0 263 | 15680587,Male,36,144000,1 264 | 15672821,Female,55,125000,1 265 | 15767681,Female,35,72000,0 266 | 15600379,Male,48,90000,1 267 | 15801336,Female,42,108000,1 268 | 15721592,Male,40,75000,0 269 | 15581282,Male,37,74000,0 270 | 15746203,Female,47,144000,1 271 | 15583137,Male,40,61000,0 272 | 15680752,Female,43,133000,0 273 | 15688172,Female,59,76000,1 274 | 15791373,Male,60,42000,1 275 | 15589449,Male,39,106000,1 276 | 15692819,Female,57,26000,1 277 | 15727467,Male,57,74000,1 278 | 15734312,Male,38,71000,0 279 | 15764604,Male,49,88000,1 280 | 15613014,Female,52,38000,1 281 | 15759684,Female,50,36000,1 282 | 15609669,Female,59,88000,1 283 | 15685536,Male,35,61000,0 284 | 15750447,Male,37,70000,1 285 | 15663249,Female,52,21000,1 286 | 15638646,Male,48,141000,0 287 | 15734161,Female,37,93000,1 288 | 15631070,Female,37,62000,0 289 | 15761950,Female,48,138000,1 290 | 15649668,Male,41,79000,0 291 | 15713912,Female,37,78000,1 292 | 15586757,Male,39,134000,1 293 | 15596522,Male,49,89000,1 294 | 15625395,Male,55,39000,1 295 | 15760570,Male,37,77000,0 296 | 15566689,Female,35,57000,0 297 | 15725794,Female,36,63000,0 298 | 15673539,Male,42,73000,1 299 | 15705298,Female,43,112000,1 300 | 15675791,Male,45,79000,0 301 | 15747043,Male,46,117000,1 302 | 15736397,Female,58,38000,1 303 | 15678201,Male,48,74000,1 304 | 15720745,Female,37,137000,1 305 | 15637593,Male,37,79000,1 306 | 15598070,Female,40,60000,0 307 | 15787550,Male,42,54000,0 308 | 15603942,Female,51,134000,0 309 | 15733973,Female,47,113000,1 310 | 15596761,Male,36,125000,1 311 | 15652400,Female,38,50000,0 312 | 15717893,Female,42,70000,0 313 | 15622585,Male,39,96000,1 314 | 15733964,Female,38,50000,0 315 | 15753861,Female,49,141000,1 316 | 15747097,Female,39,79000,0 317 | 15594762,Female,39,75000,1 318 | 15667417,Female,54,104000,1 319 | 15684861,Male,35,55000,0 320 | 15742204,Male,45,32000,1 321 | 15623502,Male,36,60000,0 322 | 15774872,Female,52,138000,1 323 | 15611191,Female,53,82000,1 324 | 15674331,Male,41,52000,0 325 | 15619465,Female,48,30000,1 326 | 15575247,Female,48,131000,1 327 | 15695679,Female,41,60000,0 328 | 15713463,Male,41,72000,0 329 | 15785170,Female,42,75000,0 330 | 15796351,Male,36,118000,1 331 | 15639576,Female,47,107000,1 332 | 15693264,Male,38,51000,0 333 | 15589715,Female,48,119000,1 334 | 15769902,Male,42,65000,0 335 | 15587177,Male,40,65000,0 336 | 15814553,Male,57,60000,1 337 | 15601550,Female,36,54000,0 338 | 15664907,Male,58,144000,1 339 | 15612465,Male,35,79000,0 340 | 15810800,Female,38,55000,0 341 | 15665760,Male,39,122000,1 342 | 15588080,Female,53,104000,1 343 | 15776844,Male,35,75000,0 344 | 15717560,Female,38,65000,0 345 | 15629739,Female,47,51000,1 346 | 15729908,Male,47,105000,1 347 | 15716781,Female,41,63000,0 348 | 15646936,Male,53,72000,1 349 | 15768151,Female,54,108000,1 350 | 15579212,Male,39,77000,0 351 | 15721835,Male,38,61000,0 352 | 15800515,Female,38,113000,1 353 | 15591279,Male,37,75000,0 354 | 15587419,Female,42,90000,1 355 | 15750335,Female,37,57000,0 356 | 15699619,Male,36,99000,1 357 | 15606472,Male,60,34000,1 358 | 15778368,Male,54,70000,1 359 | 15671387,Female,41,72000,0 360 | 15573926,Male,40,71000,1 361 | 15709183,Male,42,54000,0 362 | 15577514,Male,43,129000,1 363 | 15778830,Female,53,34000,1 364 | 15768072,Female,47,50000,1 365 | 15768293,Female,42,79000,0 366 | 15654456,Male,42,104000,1 367 | 15807525,Female,59,29000,1 368 | 15574372,Female,58,47000,1 369 | 15671249,Male,46,88000,1 370 | 15779744,Male,38,71000,0 371 | 15624755,Female,54,26000,1 372 | 15611430,Female,60,46000,1 373 | 15774744,Male,60,83000,1 374 | 15629885,Female,39,73000,0 375 | 15708791,Male,59,130000,1 376 | 15793890,Female,37,80000,0 377 | 15646091,Female,46,32000,1 378 | 15596984,Female,46,74000,0 379 | 15800215,Female,42,53000,0 380 | 15577806,Male,41,87000,1 381 | 15749381,Female,58,23000,1 382 | 15683758,Male,42,64000,0 383 | 15670615,Male,48,33000,1 384 | 15715622,Female,44,139000,1 385 | 15707634,Male,49,28000,1 386 | 15806901,Female,57,33000,1 387 | 15775335,Male,56,60000,1 388 | 15724150,Female,49,39000,1 389 | 15627220,Male,39,71000,0 390 | 15672330,Male,47,34000,1 391 | 15668521,Female,48,35000,1 392 | 15807837,Male,48,33000,1 393 | 15592570,Male,47,23000,1 394 | 15748589,Female,45,45000,1 395 | 15635893,Male,60,42000,1 396 | 15757632,Female,39,59000,0 397 | 15691863,Female,46,41000,1 398 | 15706071,Male,51,23000,1 399 | 15654296,Female,50,20000,1 400 | 15755018,Male,36,33000,0 401 | 15594041,Female,49,36000,1 -------------------------------------------------------------------------------- /day50-multiple-linear-regression/code-from-scratch.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "id": "19b4e356", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "import numpy as np\n", 11 | "from sklearn.datasets import load_diabetes" 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 22, 17 | "id": "e902ac7a", 18 | "metadata": {}, 19 | "outputs": [], 20 | "source": [ 21 | "X,y = load_diabetes(return_X_y=True)" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 23, 27 | "id": "678b82c1", 28 | "metadata": {}, 29 | "outputs": [ 30 | { 31 | "data": { 32 | "text/plain": [ 33 | "array([[ 0.03807591, 0.05068012, 0.06169621, ..., -0.00259226,\n", 34 | " 0.01990842, -0.01764613],\n", 35 | " [-0.00188202, -0.04464164, -0.05147406, ..., -0.03949338,\n", 36 | " -0.06832974, -0.09220405],\n", 37 | " [ 0.08529891, 0.05068012, 0.04445121, ..., -0.00259226,\n", 38 | " 0.00286377, -0.02593034],\n", 39 | " ...,\n", 40 | " [ 0.04170844, 0.05068012, -0.01590626, ..., -0.01107952,\n", 41 | " -0.04687948, 0.01549073],\n", 42 | " [-0.04547248, -0.04464164, 0.03906215, ..., 0.02655962,\n", 43 | " 0.04452837, -0.02593034],\n", 44 | " [-0.04547248, -0.04464164, -0.0730303 , ..., -0.03949338,\n", 45 | " -0.00421986, 0.00306441]])" 46 | ] 47 | }, 48 | "execution_count": 23, 49 | "metadata": {}, 50 | "output_type": "execute_result" 51 | } 52 | ], 53 | "source": [ 54 | "X" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": 4, 60 | "id": "afc9a715", 61 | "metadata": {}, 62 | "outputs": [ 63 | { 64 | "data": { 65 | "text/plain": [ 66 | "(442, 10)" 67 | ] 68 | }, 69 | "execution_count": 4, 70 | "metadata": {}, 71 | "output_type": "execute_result" 72 | } 73 | ], 74 | "source": [ 75 | "X.shape" 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "execution_count": 24, 81 | "id": "51c9f69b", 82 | "metadata": {}, 83 | "outputs": [ 84 | { 85 | "data": { 86 | "text/plain": [ 87 | "array([151., 75., 141., 206., 135., 97., 138., 63., 110., 310., 101.,\n", 88 | " 69., 179., 185., 118., 171., 166., 144., 97., 168., 68., 49.,\n", 89 | " 68., 245., 184., 202., 137., 85., 131., 283., 129., 59., 341.,\n", 90 | " 87., 65., 102., 265., 276., 252., 90., 100., 55., 61., 92.,\n", 91 | " 259., 53., 190., 142., 75., 142., 155., 225., 59., 104., 182.,\n", 92 | " 128., 52., 37., 170., 170., 61., 144., 52., 128., 71., 163.,\n", 93 | " 150., 97., 160., 178., 48., 270., 202., 111., 85., 42., 170.,\n", 94 | " 200., 252., 113., 143., 51., 52., 210., 65., 141., 55., 134.,\n", 95 | " 42., 111., 98., 164., 48., 96., 90., 162., 150., 279., 92.,\n", 96 | " 83., 128., 102., 302., 198., 95., 53., 134., 144., 232., 81.,\n", 97 | " 104., 59., 246., 297., 258., 229., 275., 281., 179., 200., 200.,\n", 98 | " 173., 180., 84., 121., 161., 99., 109., 115., 268., 274., 158.,\n", 99 | " 107., 83., 103., 272., 85., 280., 336., 281., 118., 317., 235.,\n", 100 | " 60., 174., 259., 178., 128., 96., 126., 288., 88., 292., 71.,\n", 101 | " 197., 186., 25., 84., 96., 195., 53., 217., 172., 131., 214.,\n", 102 | " 59., 70., 220., 268., 152., 47., 74., 295., 101., 151., 127.,\n", 103 | " 237., 225., 81., 151., 107., 64., 138., 185., 265., 101., 137.,\n", 104 | " 143., 141., 79., 292., 178., 91., 116., 86., 122., 72., 129.,\n", 105 | " 142., 90., 158., 39., 196., 222., 277., 99., 196., 202., 155.,\n", 106 | " 77., 191., 70., 73., 49., 65., 263., 248., 296., 214., 185.,\n", 107 | " 78., 93., 252., 150., 77., 208., 77., 108., 160., 53., 220.,\n", 108 | " 154., 259., 90., 246., 124., 67., 72., 257., 262., 275., 177.,\n", 109 | " 71., 47., 187., 125., 78., 51., 258., 215., 303., 243., 91.,\n", 110 | " 150., 310., 153., 346., 63., 89., 50., 39., 103., 308., 116.,\n", 111 | " 145., 74., 45., 115., 264., 87., 202., 127., 182., 241., 66.,\n", 112 | " 94., 283., 64., 102., 200., 265., 94., 230., 181., 156., 233.,\n", 113 | " 60., 219., 80., 68., 332., 248., 84., 200., 55., 85., 89.,\n", 114 | " 31., 129., 83., 275., 65., 198., 236., 253., 124., 44., 172.,\n", 115 | " 114., 142., 109., 180., 144., 163., 147., 97., 220., 190., 109.,\n", 116 | " 191., 122., 230., 242., 248., 249., 192., 131., 237., 78., 135.,\n", 117 | " 244., 199., 270., 164., 72., 96., 306., 91., 214., 95., 216.,\n", 118 | " 263., 178., 113., 200., 139., 139., 88., 148., 88., 243., 71.,\n", 119 | " 77., 109., 272., 60., 54., 221., 90., 311., 281., 182., 321.,\n", 120 | " 58., 262., 206., 233., 242., 123., 167., 63., 197., 71., 168.,\n", 121 | " 140., 217., 121., 235., 245., 40., 52., 104., 132., 88., 69.,\n", 122 | " 219., 72., 201., 110., 51., 277., 63., 118., 69., 273., 258.,\n", 123 | " 43., 198., 242., 232., 175., 93., 168., 275., 293., 281., 72.,\n", 124 | " 140., 189., 181., 209., 136., 261., 113., 131., 174., 257., 55.,\n", 125 | " 84., 42., 146., 212., 233., 91., 111., 152., 120., 67., 310.,\n", 126 | " 94., 183., 66., 173., 72., 49., 64., 48., 178., 104., 132.,\n", 127 | " 220., 57.])" 128 | ] 129 | }, 130 | "execution_count": 24, 131 | "metadata": {}, 132 | "output_type": "execute_result" 133 | } 134 | ], 135 | "source": [ 136 | "y" 137 | ] 138 | }, 139 | { 140 | "cell_type": "code", 141 | "execution_count": 25, 142 | "id": "0dec04d8", 143 | "metadata": {}, 144 | "outputs": [ 145 | { 146 | "data": { 147 | "text/plain": [ 148 | "(442,)" 149 | ] 150 | }, 151 | "execution_count": 25, 152 | "metadata": {}, 153 | "output_type": "execute_result" 154 | } 155 | ], 156 | "source": [ 157 | "y.shape" 158 | ] 159 | }, 160 | { 161 | "cell_type": "markdown", 162 | "id": "4517e3a4", 163 | "metadata": {}, 164 | "source": [ 165 | "## Using Sklearn's Linear Regression" 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": 26, 171 | "id": "5e5b799a", 172 | "metadata": {}, 173 | "outputs": [], 174 | "source": [ 175 | "from sklearn.model_selection import train_test_split" 176 | ] 177 | }, 178 | { 179 | "cell_type": "code", 180 | "execution_count": 27, 181 | "id": "254aa80e", 182 | "metadata": {}, 183 | "outputs": [], 184 | "source": [ 185 | "X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=2)" 186 | ] 187 | }, 188 | { 189 | "cell_type": "code", 190 | "execution_count": 28, 191 | "id": "9dc4933f", 192 | "metadata": {}, 193 | "outputs": [ 194 | { 195 | "name": "stdout", 196 | "output_type": "stream", 197 | "text": [ 198 | "(353, 10)\n", 199 | "(89, 10)\n" 200 | ] 201 | } 202 | ], 203 | "source": [ 204 | "print(X_train.shape)\n", 205 | "print(X_test.shape)" 206 | ] 207 | }, 208 | { 209 | "cell_type": "code", 210 | "execution_count": 29, 211 | "id": "f5368101", 212 | "metadata": {}, 213 | "outputs": [], 214 | "source": [ 215 | "from sklearn.linear_model import LinearRegression" 216 | ] 217 | }, 218 | { 219 | "cell_type": "code", 220 | "execution_count": 30, 221 | "id": "1e6811b2", 222 | "metadata": {}, 223 | "outputs": [], 224 | "source": [ 225 | "reg = LinearRegression()" 226 | ] 227 | }, 228 | { 229 | "cell_type": "code", 230 | "execution_count": 31, 231 | "id": "37c0a51f", 232 | "metadata": {}, 233 | "outputs": [ 234 | { 235 | "data": { 236 | "text/plain": [ 237 | "LinearRegression()" 238 | ] 239 | }, 240 | "execution_count": 31, 241 | "metadata": {}, 242 | "output_type": "execute_result" 243 | } 244 | ], 245 | "source": [ 246 | "reg.fit(X_train,y_train)" 247 | ] 248 | }, 249 | { 250 | "cell_type": "code", 251 | "execution_count": 32, 252 | "id": "459d66cd", 253 | "metadata": {}, 254 | "outputs": [], 255 | "source": [ 256 | "y_pred = reg.predict(X_test)" 257 | ] 258 | }, 259 | { 260 | "cell_type": "code", 261 | "execution_count": 33, 262 | "id": "477f8286", 263 | "metadata": {}, 264 | "outputs": [], 265 | "source": [ 266 | "from sklearn.metrics import r2_score" 267 | ] 268 | }, 269 | { 270 | "cell_type": "code", 271 | "execution_count": 34, 272 | "id": "38f806a7", 273 | "metadata": {}, 274 | "outputs": [ 275 | { 276 | "data": { 277 | "text/plain": [ 278 | "0.4399387660024645" 279 | ] 280 | }, 281 | "execution_count": 34, 282 | "metadata": {}, 283 | "output_type": "execute_result" 284 | } 285 | ], 286 | "source": [ 287 | "r2_score(y_test,y_pred)" 288 | ] 289 | }, 290 | { 291 | "cell_type": "code", 292 | "execution_count": 35, 293 | "id": "1c6fa7d4", 294 | "metadata": {}, 295 | "outputs": [ 296 | { 297 | "data": { 298 | "text/plain": [ 299 | "array([ -9.16088483, -205.46225988, 516.68462383, 340.62734108,\n", 300 | " -895.54360867, 561.21453306, 153.88478595, 126.73431596,\n", 301 | " 861.12139955, 52.41982836])" 302 | ] 303 | }, 304 | "execution_count": 35, 305 | "metadata": {}, 306 | "output_type": "execute_result" 307 | } 308 | ], 309 | "source": [ 310 | "reg.coef_" 311 | ] 312 | }, 313 | { 314 | "cell_type": "code", 315 | "execution_count": 36, 316 | "id": "9309c622", 317 | "metadata": {}, 318 | "outputs": [ 319 | { 320 | "data": { 321 | "text/plain": [ 322 | "151.88334520854633" 323 | ] 324 | }, 325 | "execution_count": 36, 326 | "metadata": {}, 327 | "output_type": "execute_result" 328 | } 329 | ], 330 | "source": [ 331 | "reg.intercept_" 332 | ] 333 | }, 334 | { 335 | "cell_type": "markdown", 336 | "id": "b84b1302", 337 | "metadata": {}, 338 | "source": [ 339 | "## Making our own Linear Regression Class" 340 | ] 341 | }, 342 | { 343 | "cell_type": "code", 344 | "execution_count": 54, 345 | "id": "a2aaf825", 346 | "metadata": {}, 347 | "outputs": [], 348 | "source": [ 349 | "class MeraLR:\n", 350 | " \n", 351 | " def __init__(self):\n", 352 | " self.coef_ = None\n", 353 | " self.intercept_ = None\n", 354 | " \n", 355 | " def fit(self,X_train,y_train):\n", 356 | " X_train = np.insert(X_train,0,1,axis=1)\n", 357 | " \n", 358 | " # calcuate the coeffs\n", 359 | " betas = np.linalg.inv(np.dot(X_train.T,X_train)).dot(X_train.T).dot(y_train)\n", 360 | " self.intercept_ = betas[0]\n", 361 | " self.coef_ = betas[1:]\n", 362 | " \n", 363 | " def predict(self,X_test):\n", 364 | " y_pred = np.dot(X_test,self.coef_) + self.intercept_\n", 365 | " return y_pred\n", 366 | " \n", 367 | " " 368 | ] 369 | }, 370 | { 371 | "cell_type": "code", 372 | "execution_count": 55, 373 | "id": "2f6a0efc", 374 | "metadata": {}, 375 | "outputs": [], 376 | "source": [ 377 | "lr = MeraLR()" 378 | ] 379 | }, 380 | { 381 | "cell_type": "code", 382 | "execution_count": 56, 383 | "id": "d3a93648", 384 | "metadata": {}, 385 | "outputs": [], 386 | "source": [ 387 | "lr.fit(X_train,y_train)" 388 | ] 389 | }, 390 | { 391 | "cell_type": "code", 392 | "execution_count": 43, 393 | "id": "f1b95f47", 394 | "metadata": {}, 395 | "outputs": [ 396 | { 397 | "data": { 398 | "text/plain": [ 399 | "(353, 10)" 400 | ] 401 | }, 402 | "execution_count": 43, 403 | "metadata": {}, 404 | "output_type": "execute_result" 405 | } 406 | ], 407 | "source": [ 408 | "X_train.shape" 409 | ] 410 | }, 411 | { 412 | "cell_type": "code", 413 | "execution_count": 44, 414 | "id": "d667c2af", 415 | "metadata": {}, 416 | "outputs": [ 417 | { 418 | "data": { 419 | "text/plain": [ 420 | "(353, 11)" 421 | ] 422 | }, 423 | "execution_count": 44, 424 | "metadata": {}, 425 | "output_type": "execute_result" 426 | } 427 | ], 428 | "source": [ 429 | "np.insert(X_train,0,1,axis=1).shape" 430 | ] 431 | }, 432 | { 433 | "cell_type": "code", 434 | "execution_count": 58, 435 | "id": "9525f2d5", 436 | "metadata": {}, 437 | "outputs": [], 438 | "source": [ 439 | "y_pred = lr.predict(X_test)" 440 | ] 441 | }, 442 | { 443 | "cell_type": "code", 444 | "execution_count": 59, 445 | "id": "106d789d", 446 | "metadata": {}, 447 | "outputs": [ 448 | { 449 | "data": { 450 | "text/plain": [ 451 | "0.43993876600246407" 452 | ] 453 | }, 454 | "execution_count": 59, 455 | "metadata": {}, 456 | "output_type": "execute_result" 457 | } 458 | ], 459 | "source": [ 460 | "r2_score(y_test,y_pred)" 461 | ] 462 | }, 463 | { 464 | "cell_type": "code", 465 | "execution_count": 60, 466 | "id": "f0245b9f", 467 | "metadata": {}, 468 | "outputs": [ 469 | { 470 | "data": { 471 | "text/plain": [ 472 | "array([ -9.16088483, -205.46225988, 516.68462383, 340.62734108,\n", 473 | " -895.54360867, 561.21453306, 153.88478595, 126.73431596,\n", 474 | " 861.12139955, 52.41982836])" 475 | ] 476 | }, 477 | "execution_count": 60, 478 | "metadata": {}, 479 | "output_type": "execute_result" 480 | } 481 | ], 482 | "source": [ 483 | "lr.coef_" 484 | ] 485 | }, 486 | { 487 | "cell_type": "code", 488 | "execution_count": 61, 489 | "id": "9df66921", 490 | "metadata": {}, 491 | "outputs": [ 492 | { 493 | "data": { 494 | "text/plain": [ 495 | "151.8833452085463" 496 | ] 497 | }, 498 | "execution_count": 61, 499 | "metadata": {}, 500 | "output_type": "execute_result" 501 | } 502 | ], 503 | "source": [ 504 | "lr.intercept_" 505 | ] 506 | }, 507 | { 508 | "cell_type": "code", 509 | "execution_count": null, 510 | "id": "9b58b5ed", 511 | "metadata": {}, 512 | "outputs": [], 513 | "source": [] 514 | } 515 | ], 516 | "metadata": { 517 | "kernelspec": { 518 | "display_name": "Python 3", 519 | "language": "python", 520 | "name": "python3" 521 | }, 522 | "language_info": { 523 | "codemirror_mode": { 524 | "name": "ipython", 525 | "version": 3 526 | }, 527 | "file_extension": ".py", 528 | "mimetype": "text/x-python", 529 | "name": "python", 530 | "nbconvert_exporter": "python", 531 | "pygments_lexer": "ipython3", 532 | "version": "3.8.8" 533 | } 534 | }, 535 | "nbformat": 4, 536 | "nbformat_minor": 5 537 | } 538 | -------------------------------------------------------------------------------- /day51-gradient-descent/gradient-descent-code-from-scratch.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 60, 6 | "id": "480410b3", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "from sklearn.datasets import make_regression\n", 11 | "import matplotlib.pyplot as plt\n", 12 | "import numpy as np\n", 13 | "from sklearn.model_selection import cross_val_score" 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": 73, 19 | "id": "a720e496", 20 | "metadata": {}, 21 | "outputs": [], 22 | "source": [ 23 | "X,y = make_regression(n_samples=100, n_features=1, n_informative=1, n_targets=1,noise=20,random_state=13)" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": 74, 29 | "id": "623ddc39", 30 | "metadata": {}, 31 | "outputs": [ 32 | { 33 | "data": { 34 | "text/plain": [ 35 | "" 36 | ] 37 | }, 38 | "execution_count": 74, 39 | "metadata": {}, 40 | "output_type": "execute_result" 41 | }, 42 | { 43 | "data": { 44 | "image/png": "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\n", 45 | "text/plain": [ 46 | "
" 47 | ] 48 | }, 49 | "metadata": { 50 | "needs_background": "light" 51 | }, 52 | "output_type": "display_data" 53 | } 54 | ], 55 | "source": [ 56 | "plt.scatter(X,y)" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 111, 62 | "id": "fb217682", 63 | "metadata": {}, 64 | "outputs": [], 65 | "source": [ 66 | "from sklearn.model_selection import train_test_split\n", 67 | "X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=2)" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": 112, 73 | "id": "1c75b68c", 74 | "metadata": {}, 75 | "outputs": [], 76 | "source": [ 77 | "from sklearn.linear_model import LinearRegression" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 113, 83 | "id": "7f55ab93", 84 | "metadata": {}, 85 | "outputs": [], 86 | "source": [ 87 | "lr = LinearRegression()" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": 114, 93 | "id": "8a9b8dab", 94 | "metadata": {}, 95 | "outputs": [ 96 | { 97 | "name": "stdout", 98 | "output_type": "stream", 99 | "text": [ 100 | "[28.12597332]\n", 101 | "-2.271014426178382\n" 102 | ] 103 | } 104 | ], 105 | "source": [ 106 | "lr.fit(X_train,y_train)\n", 107 | "print(lr.coef_)\n", 108 | "print(lr.intercept_)" 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": 115, 114 | "id": "a1891526", 115 | "metadata": {}, 116 | "outputs": [ 117 | { 118 | "data": { 119 | "text/plain": [ 120 | "0.6345158782661013" 121 | ] 122 | }, 123 | "execution_count": 115, 124 | "metadata": {}, 125 | "output_type": "execute_result" 126 | } 127 | ], 128 | "source": [ 129 | "y_pred = lr.predict(X_test)\n", 130 | "from sklearn.metrics import r2_score\n", 131 | "r2_score(y_test,y_pred)" 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": 106, 137 | "id": "0a55c997", 138 | "metadata": {}, 139 | "outputs": [], 140 | "source": [ 141 | "class GDRegressor:\n", 142 | " \n", 143 | " def __init__(self,learning_rate,epochs):\n", 144 | " self.m = 100\n", 145 | " self.b = -120\n", 146 | " self.lr = learning_rate\n", 147 | " self.epochs = epochs\n", 148 | " \n", 149 | " def fit(self,X,y):\n", 150 | " # calcualte the b using GD\n", 151 | " for i in range(self.epochs):\n", 152 | " loss_slope_b = -2 * np.sum(y - self.m*X.ravel() - self.b)\n", 153 | " loss_slope_m = -2 * np.sum((y - self.m*X.ravel() - self.b)*X.ravel())\n", 154 | " \n", 155 | " self.b = self.b - (self.lr * loss_slope_b)\n", 156 | " self.m = self.m - (self.lr * loss_slope_m)\n", 157 | " print(self.m,self.b)\n", 158 | " \n", 159 | " def predict(self,X):\n", 160 | " return self.m * X + self.b\n", 161 | " " 162 | ] 163 | }, 164 | { 165 | "cell_type": "code", 166 | "execution_count": 116, 167 | "id": "916c1a07", 168 | "metadata": {}, 169 | "outputs": [], 170 | "source": [ 171 | "gd = GDRegressor(0.001,50)" 172 | ] 173 | }, 174 | { 175 | "cell_type": "code", 176 | "execution_count": 117, 177 | "id": "fb9c36f3", 178 | "metadata": {}, 179 | "outputs": [ 180 | { 181 | "name": "stdout", 182 | "output_type": "stream", 183 | "text": [ 184 | "28.159367347119066 -2.3004574196824854\n" 185 | ] 186 | } 187 | ], 188 | "source": [ 189 | "gd.fit(X_train,y_train)" 190 | ] 191 | }, 192 | { 193 | "cell_type": "code", 194 | "execution_count": 118, 195 | "id": "bcd8f1cb", 196 | "metadata": {}, 197 | "outputs": [ 198 | { 199 | "data": { 200 | "text/plain": [ 201 | "0.6343842836315579" 202 | ] 203 | }, 204 | "execution_count": 118, 205 | "metadata": {}, 206 | "output_type": "execute_result" 207 | } 208 | ], 209 | "source": [ 210 | "y_pred = gd.predict(X_test)\n", 211 | "from sklearn.metrics import r2_score\n", 212 | "r2_score(y_test,y_pred)" 213 | ] 214 | }, 215 | { 216 | "cell_type": "code", 217 | "execution_count": null, 218 | "id": "68858bae", 219 | "metadata": {}, 220 | "outputs": [], 221 | "source": [] 222 | } 223 | ], 224 | "metadata": { 225 | "kernelspec": { 226 | "display_name": "Python 3", 227 | "language": "python", 228 | "name": "python3" 229 | }, 230 | "language_info": { 231 | "codemirror_mode": { 232 | "name": "ipython", 233 | "version": 3 234 | }, 235 | "file_extension": ".py", 236 | "mimetype": "text/x-python", 237 | "name": "python", 238 | "nbconvert_exporter": "python", 239 | "pygments_lexer": "ipython3", 240 | "version": "3.8.8" 241 | } 242 | }, 243 | "nbformat": 4, 244 | "nbformat_minor": 5 245 | } 246 | -------------------------------------------------------------------------------- /day28-column-transformer/day28.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 75, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "import numpy as np\n", 10 | "import pandas as pd" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 76, 16 | "metadata": {}, 17 | "outputs": [], 18 | "source": [ 19 | "from sklearn.impute import SimpleImputer\n", 20 | "from sklearn.preprocessing import OneHotEncoder\n", 21 | "from sklearn.preprocessing import OrdinalEncoder" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 77, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "df = pd.read_csv('covid_toy.csv')" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 27, 36 | "metadata": {}, 37 | "outputs": [ 38 | { 39 | "data": { 40 | "text/html": [ 41 | "
\n", 42 | "\n", 55 | "\n", 56 | " \n", 57 | " \n", 58 | " \n", 59 | " \n", 60 | " \n", 61 | " \n", 62 | " \n", 63 | " \n", 64 | " \n", 65 | " \n", 66 | " \n", 67 | " \n", 68 | " \n", 69 | " \n", 70 | " \n", 71 | " \n", 72 | " \n", 73 | " \n", 74 | " \n", 75 | " \n", 76 | " \n", 77 | " \n", 78 | " \n", 79 | " \n", 80 | " \n", 81 | " \n", 82 | " \n", 83 | " \n", 84 | " \n", 85 | " \n", 86 | " \n", 87 | " \n", 88 | " \n", 89 | " \n", 90 | " \n", 91 | " \n", 92 | " \n", 93 | " \n", 94 | " \n", 95 | " \n", 96 | " \n", 97 | " \n", 98 | " \n", 99 | " \n", 100 | " \n", 101 | " \n", 102 | " \n", 103 | " \n", 104 | " \n", 105 | " \n", 106 | " \n", 107 | " \n", 108 | " \n", 109 | " \n", 110 | " \n", 111 | " \n", 112 | " \n", 113 | " \n", 114 | "
agegenderfevercoughcityhas_covid
060Male103.0MildKolkataNo
127Male100.0MildDelhiYes
242Male101.0MildDelhiNo
331Female98.0MildKolkataNo
465Female101.0MildMumbaiNo
\n", 115 | "
" 116 | ], 117 | "text/plain": [ 118 | " age gender fever cough city has_covid\n", 119 | "0 60 Male 103.0 Mild Kolkata No\n", 120 | "1 27 Male 100.0 Mild Delhi Yes\n", 121 | "2 42 Male 101.0 Mild Delhi No\n", 122 | "3 31 Female 98.0 Mild Kolkata No\n", 123 | "4 65 Female 101.0 Mild Mumbai No" 124 | ] 125 | }, 126 | "execution_count": 27, 127 | "metadata": {}, 128 | "output_type": "execute_result" 129 | } 130 | ], 131 | "source": [ 132 | "df.head()" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": 80, 138 | "metadata": {}, 139 | "outputs": [ 140 | { 141 | "data": { 142 | "text/plain": [ 143 | "age 0\n", 144 | "gender 0\n", 145 | "fever 10\n", 146 | "cough 0\n", 147 | "city 0\n", 148 | "has_covid 0\n", 149 | "dtype: int64" 150 | ] 151 | }, 152 | "execution_count": 80, 153 | "metadata": {}, 154 | "output_type": "execute_result" 155 | } 156 | ], 157 | "source": [ 158 | "df.isnull().sum()" 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": 29, 164 | "metadata": {}, 165 | "outputs": [], 166 | "source": [ 167 | "from sklearn.model_selection import train_test_split\n", 168 | "X_train,X_test,y_train,y_test = train_test_split(df.drop(columns=['has_covid']),df['has_covid'],\n", 169 | " test_size=0.2)" 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": 81, 175 | "metadata": {}, 176 | "outputs": [ 177 | { 178 | "data": { 179 | "text/html": [ 180 | "
\n", 181 | "\n", 194 | "\n", 195 | " \n", 196 | " \n", 197 | " \n", 198 | " \n", 199 | " \n", 200 | " \n", 201 | " \n", 202 | " \n", 203 | " \n", 204 | " \n", 205 | " \n", 206 | " \n", 207 | " \n", 208 | " \n", 209 | " \n", 210 | " \n", 211 | " \n", 212 | " \n", 213 | " \n", 214 | " \n", 215 | " \n", 216 | " \n", 217 | " \n", 218 | " \n", 219 | " \n", 220 | " \n", 221 | " \n", 222 | " \n", 223 | " \n", 224 | " \n", 225 | " \n", 226 | " \n", 227 | " \n", 228 | " \n", 229 | " \n", 230 | " \n", 231 | " \n", 232 | " \n", 233 | " \n", 234 | " \n", 235 | " \n", 236 | " \n", 237 | " \n", 238 | " \n", 239 | " \n", 240 | " \n", 241 | " \n", 242 | " \n", 243 | " \n", 244 | " \n", 245 | " \n", 246 | " \n", 247 | " \n", 248 | " \n", 249 | " \n", 250 | " \n", 251 | " \n", 252 | " \n", 253 | " \n", 254 | " \n", 255 | " \n", 256 | " \n", 257 | " \n", 258 | " \n", 259 | " \n", 260 | " \n", 261 | " \n", 262 | " \n", 263 | " \n", 264 | " \n", 265 | " \n", 266 | " \n", 267 | " \n", 268 | " \n", 269 | " \n", 270 | " \n", 271 | " \n", 272 | " \n", 273 | " \n", 274 | " \n", 275 | " \n", 276 | " \n", 277 | " \n", 278 | " \n", 279 | " \n", 280 | " \n", 281 | " \n", 282 | " \n", 283 | " \n", 284 | " \n", 285 | " \n", 286 | " \n", 287 | " \n", 288 | " \n", 289 | " \n", 290 | " \n", 291 | " \n", 292 | " \n", 293 | " \n", 294 | " \n", 295 | "
agegenderfevercoughcity
5581Female101.0MildMumbai
7680Male100.0MildBangalore
2271Female98.0StrongKolkata
9327Male100.0MildKolkata
3326Female98.0MildKolkata
..................
242Male101.0MildDelhi
5111Female100.0StrongKolkata
584FemaleNaNMildBangalore
4049Female102.0MildDelhi
1942FemaleNaNStrongBangalore
\n", 296 | "

80 rows × 5 columns

\n", 297 | "
" 298 | ], 299 | "text/plain": [ 300 | " age gender fever cough city\n", 301 | "55 81 Female 101.0 Mild Mumbai\n", 302 | "76 80 Male 100.0 Mild Bangalore\n", 303 | "22 71 Female 98.0 Strong Kolkata\n", 304 | "93 27 Male 100.0 Mild Kolkata\n", 305 | "33 26 Female 98.0 Mild Kolkata\n", 306 | ".. ... ... ... ... ...\n", 307 | "2 42 Male 101.0 Mild Delhi\n", 308 | "51 11 Female 100.0 Strong Kolkata\n", 309 | "5 84 Female NaN Mild Bangalore\n", 310 | "40 49 Female 102.0 Mild Delhi\n", 311 | "19 42 Female NaN Strong Bangalore\n", 312 | "\n", 313 | "[80 rows x 5 columns]" 314 | ] 315 | }, 316 | "execution_count": 81, 317 | "metadata": {}, 318 | "output_type": "execute_result" 319 | } 320 | ], 321 | "source": [ 322 | "X_train" 323 | ] 324 | }, 325 | { 326 | "cell_type": "markdown", 327 | "metadata": {}, 328 | "source": [ 329 | "## 1. Aam Zindagi" 330 | ] 331 | }, 332 | { 333 | "cell_type": "code", 334 | "execution_count": 83, 335 | "metadata": {}, 336 | "outputs": [ 337 | { 338 | "data": { 339 | "text/plain": [ 340 | "(80, 1)" 341 | ] 342 | }, 343 | "execution_count": 83, 344 | "metadata": {}, 345 | "output_type": "execute_result" 346 | } 347 | ], 348 | "source": [ 349 | "# adding simple imputer to fever col\n", 350 | "si = SimpleImputer()\n", 351 | "X_train_fever = si.fit_transform(X_train[['fever']])\n", 352 | "\n", 353 | "# also the test data\n", 354 | "X_test_fever = si.fit_transform(X_test[['fever']])\n", 355 | " \n", 356 | "X_train_fever.shape" 357 | ] 358 | }, 359 | { 360 | "cell_type": "code", 361 | "execution_count": 85, 362 | "metadata": {}, 363 | "outputs": [ 364 | { 365 | "data": { 366 | "text/plain": [ 367 | "(80, 1)" 368 | ] 369 | }, 370 | "execution_count": 85, 371 | "metadata": {}, 372 | "output_type": "execute_result" 373 | } 374 | ], 375 | "source": [ 376 | "# Ordinalencoding -> cough\n", 377 | "oe = OrdinalEncoder(categories=[['Mild','Strong']])\n", 378 | "X_train_cough = oe.fit_transform(X_train[['cough']])\n", 379 | "\n", 380 | "# also the test data\n", 381 | "X_test_cough = oe.fit_transform(X_test[['cough']])\n", 382 | "\n", 383 | "X_train_cough.shape" 384 | ] 385 | }, 386 | { 387 | "cell_type": "code", 388 | "execution_count": 87, 389 | "metadata": {}, 390 | "outputs": [ 391 | { 392 | "data": { 393 | "text/plain": [ 394 | "(80, 4)" 395 | ] 396 | }, 397 | "execution_count": 87, 398 | "metadata": {}, 399 | "output_type": "execute_result" 400 | } 401 | ], 402 | "source": [ 403 | "# OneHotEncoding -> gender,city\n", 404 | "ohe = OneHotEncoder(drop='first',sparse=False)\n", 405 | "X_train_gender_city = ohe.fit_transform(X_train[['gender','city']])\n", 406 | "\n", 407 | "# also the test data\n", 408 | "X_test_gender_city = ohe.fit_transform(X_test[['gender','city']])\n", 409 | "\n", 410 | "X_train_gender_city.shape" 411 | ] 412 | }, 413 | { 414 | "cell_type": "code", 415 | "execution_count": 89, 416 | "metadata": {}, 417 | "outputs": [ 418 | { 419 | "data": { 420 | "text/plain": [ 421 | "(80, 1)" 422 | ] 423 | }, 424 | "execution_count": 89, 425 | "metadata": {}, 426 | "output_type": "execute_result" 427 | } 428 | ], 429 | "source": [ 430 | "# Extracting Age\n", 431 | "X_train_age = X_train.drop(columns=['gender','fever','cough','city']).values\n", 432 | "\n", 433 | "# also the test data\n", 434 | "X_test_age = X_test.drop(columns=['gender','fever','cough','city']).values\n", 435 | "\n", 436 | "X_train_age.shape" 437 | ] 438 | }, 439 | { 440 | "cell_type": "code", 441 | "execution_count": 92, 442 | "metadata": {}, 443 | "outputs": [ 444 | { 445 | "data": { 446 | "text/plain": [ 447 | "(80, 7)" 448 | ] 449 | }, 450 | "execution_count": 92, 451 | "metadata": {}, 452 | "output_type": "execute_result" 453 | } 454 | ], 455 | "source": [ 456 | "X_train_transformed = np.concatenate((X_train_age,X_train_fever,X_train_gender_city,X_train_cough),axis=1)\n", 457 | "# also the test data\n", 458 | "X_test_transformed = np.concatenate((X_test_age,X_test_fever,X_test_gender_city,X_test_cough),axis=1)\n", 459 | "\n", 460 | "X_train_transformed.shape" 461 | ] 462 | }, 463 | { 464 | "cell_type": "markdown", 465 | "metadata": {}, 466 | "source": [ 467 | "## Mentos Zindagi" 468 | ] 469 | }, 470 | { 471 | "cell_type": "code", 472 | "execution_count": 32, 473 | "metadata": {}, 474 | "outputs": [], 475 | "source": [ 476 | "from sklearn.compose import ColumnTransformer" 477 | ] 478 | }, 479 | { 480 | "cell_type": "code", 481 | "execution_count": 95, 482 | "metadata": {}, 483 | "outputs": [], 484 | "source": [ 485 | "transformer = ColumnTransformer(transformers=[\n", 486 | " ('tnf1',SimpleImputer(),['fever']),\n", 487 | " ('tnf2',OrdinalEncoder(categories=[['Mild','Strong']]),['cough']),\n", 488 | " ('tnf3',OneHotEncoder(sparse=False,drop='first'),['gender','city'])\n", 489 | "],remainder='passthrough')" 490 | ] 491 | }, 492 | { 493 | "cell_type": "code", 494 | "execution_count": 97, 495 | "metadata": {}, 496 | "outputs": [ 497 | { 498 | "data": { 499 | "text/plain": [ 500 | "(80, 7)" 501 | ] 502 | }, 503 | "execution_count": 97, 504 | "metadata": {}, 505 | "output_type": "execute_result" 506 | } 507 | ], 508 | "source": [ 509 | "transformer.fit_transform(X_train).shape" 510 | ] 511 | }, 512 | { 513 | "cell_type": "code", 514 | "execution_count": 99, 515 | "metadata": {}, 516 | "outputs": [ 517 | { 518 | "data": { 519 | "text/plain": [ 520 | "(20, 7)" 521 | ] 522 | }, 523 | "execution_count": 99, 524 | "metadata": {}, 525 | "output_type": "execute_result" 526 | } 527 | ], 528 | "source": [ 529 | "transformer.transform(X_test).shape" 530 | ] 531 | }, 532 | { 533 | "cell_type": "code", 534 | "execution_count": null, 535 | "metadata": {}, 536 | "outputs": [], 537 | "source": [] 538 | } 539 | ], 540 | "metadata": { 541 | "kernelspec": { 542 | "display_name": "Python 3", 543 | "language": "python", 544 | "name": "python3" 545 | }, 546 | "language_info": { 547 | "codemirror_mode": { 548 | "name": "ipython", 549 | "version": 3 550 | }, 551 | "file_extension": ".py", 552 | "mimetype": "text/x-python", 553 | "name": "python", 554 | "nbconvert_exporter": "python", 555 | "pygments_lexer": "ipython3", 556 | "version": "3.8.3" 557 | } 558 | }, 559 | "nbformat": 4, 560 | "nbformat_minor": 4 561 | } 562 | --------------------------------------------------------------------------------