{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n%matplotlib inline\nfrom sklearn.impute import SimpleImputer\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.neighbors import KNeighborsClassifier\nfrom sklearn.model_selection import train_test_split\n#from datasist.structdata import detect_outliers\nfrom sklearn.metrics import r2_score, mean_absolute_error, mean_squared_error\nfrom sklearn.svm import SVC\nfrom sklearn.metrics import accuracy_score\nfrom sklearn.ensemble import RandomForestClassifier\n       \n        \n# data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('../input/big-data-derby-2022/nyra_2019_complete.csv'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-11-14T16:45:57.718406Z","iopub.execute_input":"2022-11-14T16:45:57.718854Z","iopub.status.idle":"2022-11-14T16:45:57.733270Z","shell.execute_reply.started":"2022-11-14T16:45:57.718796Z","shell.execute_reply":"2022-11-14T16:45:57.731912Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"horse=pd.read_csv('../input/bigdatadebry/nyra_2019_complete.csv')","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:45:57.735230Z","iopub.execute_input":"2022-11-14T16:45:57.735581Z","iopub.status.idle":"2022-11-14T16:46:07.968491Z","shell.execute_reply.started":"2022-11-14T16:45:57.735551Z","shell.execute_reply":"2022-11-14T16:46:07.967348Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"horse.head(3)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:07.969930Z","iopub.execute_input":"2022-11-14T16:46:07.970280Z","iopub.status.idle":"2022-11-14T16:46:07.990772Z","shell.execute_reply.started":"2022-11-14T16:46:07.970249Z","shell.execute_reply":"2022-11-14T16:46:07.989563Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"horse.info()","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:07.993226Z","iopub.execute_input":"2022-11-14T16:46:07.994363Z","iopub.status.idle":"2022-11-14T16:46:08.010511Z","shell.execute_reply.started":"2022-11-14T16:46:07.994310Z","shell.execute_reply":"2022-11-14T16:46:08.008928Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"horse.describe()","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:08.012208Z","iopub.execute_input":"2022-11-14T16:46:08.012712Z","iopub.status.idle":"2022-11-14T16:46:09.300640Z","shell.execute_reply.started":"2022-11-14T16:46:08.012675Z","shell.execute_reply":"2022-11-14T16:46:09.299380Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"horse.shape","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:09.302560Z","iopub.execute_input":"2022-11-14T16:46:09.303336Z","iopub.status.idle":"2022-11-14T16:46:09.311304Z","shell.execute_reply.started":"2022-11-14T16:46:09.303288Z","shell.execute_reply":"2022-11-14T16:46:09.310050Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"horse.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:09.313128Z","iopub.execute_input":"2022-11-14T16:46:09.313585Z","iopub.status.idle":"2022-11-14T16:46:10.953897Z","shell.execute_reply.started":"2022-11-14T16:46:09.313552Z","shell.execute_reply":"2022-11-14T16:46:10.952666Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"horse['track_id'].value_counts().plot(kind='pie')","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:10.955156Z","iopub.execute_input":"2022-11-14T16:46:10.956164Z","iopub.status.idle":"2022-11-14T16:46:11.352381Z","shell.execute_reply.started":"2022-11-14T16:46:10.956130Z","shell.execute_reply":"2022-11-14T16:46:11.351576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"horse['course_type'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:11.357204Z","iopub.execute_input":"2022-11-14T16:46:11.358268Z","iopub.status.idle":"2022-11-14T16:46:11.661223Z","shell.execute_reply.started":"2022-11-14T16:46:11.358197Z","shell.execute_reply":"2022-11-14T16:46:11.659742Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"horse['race_type'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:11.663190Z","iopub.execute_input":"2022-11-14T16:46:11.663703Z","iopub.status.idle":"2022-11-14T16:46:11.993083Z","shell.execute_reply.started":"2022-11-14T16:46:11.663655Z","shell.execute_reply":"2022-11-14T16:46:11.991894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"horse['jockey'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:11.994749Z","iopub.execute_input":"2022-11-14T16:46:11.995545Z","iopub.status.idle":"2022-11-14T16:46:12.328546Z","shell.execute_reply.started":"2022-11-14T16:46:11.995500Z","shell.execute_reply":"2022-11-14T16:46:12.327176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"horse['race_date'].max()","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:12.330214Z","iopub.execute_input":"2022-11-14T16:46:12.330676Z","iopub.status.idle":"2022-11-14T16:46:12.689051Z","shell.execute_reply.started":"2022-11-14T16:46:12.330634Z","shell.execute_reply":"2022-11-14T16:46:12.688147Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"horse['race_date'].head(11)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:12.690077Z","iopub.execute_input":"2022-11-14T16:46:12.690426Z","iopub.status.idle":"2022-11-14T16:46:12.699436Z","shell.execute_reply.started":"2022-11-14T16:46:12.690396Z","shell.execute_reply":"2022-11-14T16:46:12.698123Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"horse.duplicated()","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:12.701551Z","iopub.execute_input":"2022-11-14T16:46:12.702052Z","iopub.status.idle":"2022-11-14T16:46:20.921805Z","shell.execute_reply.started":"2022-11-14T16:46:12.702008Z","shell.execute_reply":"2022-11-14T16:46:20.920635Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"horse['race_date'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:20.923305Z","iopub.execute_input":"2022-11-14T16:46:20.923664Z","iopub.status.idle":"2022-11-14T16:46:21.265098Z","shell.execute_reply.started":"2022-11-14T16:46:20.923632Z","shell.execute_reply":"2022-11-14T16:46:21.263782Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"horse['odds']=(horse['odds']/100)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:21.266629Z","iopub.execute_input":"2022-11-14T16:46:21.267109Z","iopub.status.idle":"2022-11-14T16:46:21.350905Z","shell.execute_reply.started":"2022-11-14T16:46:21.267066Z","shell.execute_reply":"2022-11-14T16:46:21.349884Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"horse['distance_id']=horse['distance_id']/100","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:21.352199Z","iopub.execute_input":"2022-11-14T16:46:21.352633Z","iopub.status.idle":"2022-11-14T16:46:21.477813Z","shell.execute_reply.started":"2022-11-14T16:46:21.352592Z","shell.execute_reply":"2022-11-14T16:46:21.476569Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15,7))\nsns.heatmap(horse.corr(),annot=True)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:21.479349Z","iopub.execute_input":"2022-11-14T16:46:21.479694Z","iopub.status.idle":"2022-11-14T16:46:24.213222Z","shell.execute_reply.started":"2022-11-14T16:46:21.479662Z","shell.execute_reply":"2022-11-14T16:46:24.211926Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#n=['race_number','program_number','trakus_index','latitude','longitude','distance_id','run_up_distance','purse','post_time','weight_carried','odds']\\n\",\n        #for col in n:\n        #outliers=detect_outliers(horse,0,[col])\n        #horse.drop(outliers,inplace=True)\n        #print(len(outliers))","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:24.215467Z","iopub.execute_input":"2022-11-14T16:46:24.216469Z","iopub.status.idle":"2022-11-14T16:46:24.222806Z","shell.execute_reply.started":"2022-11-14T16:46:24.216418Z","shell.execute_reply":"2022-11-14T16:46:24.221252Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#one hot encoding\nhorse=pd.get_dummies(horse,columns=['track_id','course_type','track_condition','race_type'],drop_first=True)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:24.225315Z","iopub.execute_input":"2022-11-14T16:46:24.226178Z","iopub.status.idle":"2022-11-14T16:46:27.655618Z","shell.execute_reply.started":"2022-11-14T16:46:24.226130Z","shell.execute_reply":"2022-11-14T16:46:27.654431Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"h1=horse\nh1","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:27.657259Z","iopub.execute_input":"2022-11-14T16:46:27.657625Z","iopub.status.idle":"2022-11-14T16:46:28.962151Z","shell.execute_reply.started":"2022-11-14T16:46:27.657594Z","shell.execute_reply":"2022-11-14T16:46:28.960892Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"h1.info()","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:28.963996Z","iopub.execute_input":"2022-11-14T16:46:28.964930Z","iopub.status.idle":"2022-11-14T16:46:28.979051Z","shell.execute_reply.started":"2022-11-14T16:46:28.964876Z","shell.execute_reply":"2022-11-14T16:46:28.977680Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#horse['program_number']=horse['program_number'].astype('int64')","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:28.980540Z","iopub.execute_input":"2022-11-14T16:46:28.980985Z","iopub.status.idle":"2022-11-14T16:46:28.990367Z","shell.execute_reply.started":"2022-11-14T16:46:28.980948Z","shell.execute_reply":"2022-11-14T16:46:28.989293Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" #machine learning\nfeature=h1.drop(columns=['race_date','jockey','purse','program_number'],axis=1)\ntarget=h1['purse']","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:28.998582Z","iopub.execute_input":"2022-11-14T16:46:28.999033Z","iopub.status.idle":"2022-11-14T16:46:29.801151Z","shell.execute_reply.started":"2022-11-14T16:46:28.998992Z","shell.execute_reply":"2022-11-14T16:46:29.800053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train, x_test, y_train, y_test = train_test_split(feature, target, test_size=0.2, shuffle=True)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:29.802383Z","iopub.execute_input":"2022-11-14T16:46:29.802701Z","iopub.status.idle":"2022-11-14T16:46:32.894596Z","shell.execute_reply.started":"2022-11-14T16:46:29.802672Z","shell.execute_reply":"2022-11-14T16:46:32.893218Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train.shape,y_train.shape","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:32.896519Z","iopub.execute_input":"2022-11-14T16:46:32.897030Z","iopub.status.idle":"2022-11-14T16:46:32.904629Z","shell.execute_reply.started":"2022-11-14T16:46:32.896983Z","shell.execute_reply":"2022-11-14T16:46:32.903387Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#scaler= StandardScaler()","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:32.906394Z","iopub.execute_input":"2022-11-14T16:46:32.906919Z","iopub.status.idle":"2022-11-14T16:46:32.916341Z","shell.execute_reply.started":"2022-11-14T16:46:32.906871Z","shell.execute_reply":"2022-11-14T16:46:32.915272Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#StandardScaler()","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:32.917866Z","iopub.execute_input":"2022-11-14T16:46:32.918377Z","iopub.status.idle":"2022-11-14T16:46:32.928042Z","shell.execute_reply.started":"2022-11-14T16:46:32.918333Z","shell.execute_reply":"2022-11-14T16:46:32.927205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#scaler.fit(x_train)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:32.928970Z","iopub.execute_input":"2022-11-14T16:46:32.929302Z","iopub.status.idle":"2022-11-14T16:46:32.940748Z","shell.execute_reply.started":"2022-11-14T16:46:32.929272Z","shell.execute_reply":"2022-11-14T16:46:32.939694Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#x_train = scaler.transform(x_train)\n#x_test = scaler.transform(x_test)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:32.941795Z","iopub.execute_input":"2022-11-14T16:46:32.942155Z","iopub.status.idle":"2022-11-14T16:46:32.954725Z","shell.execute_reply.started":"2022-11-14T16:46:32.942118Z","shell.execute_reply":"2022-11-14T16:46:32.953570Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#knn\n#model = KNeighborsClassifier(n_neighbors=7)\n#model.fit(x_train, y_train)\n#y_pred = model.predict(x_test)\n#print(y_pred[:4])","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:32.956659Z","iopub.execute_input":"2022-11-14T16:46:32.957168Z","iopub.status.idle":"2022-11-14T16:46:32.969072Z","shell.execute_reply.started":"2022-11-14T16:46:32.957132Z","shell.execute_reply":"2022-11-14T16:46:32.967679Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#accuracy_score(y_test, y_pred)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:32.971012Z","iopub.execute_input":"2022-11-14T16:46:32.971442Z","iopub.status.idle":"2022-11-14T16:46:32.980472Z","shell.execute_reply.started":"2022-11-14T16:46:32.971398Z","shell.execute_reply":"2022-11-14T16:46:32.979597Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" #machine learning2\n#h2=horse","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:32.982109Z","iopub.execute_input":"2022-11-14T16:46:32.982519Z","iopub.status.idle":"2022-11-14T16:46:32.992461Z","shell.execute_reply.started":"2022-11-14T16:46:32.982474Z","shell.execute_reply":"2022-11-14T16:46:32.991243Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#feature=h2.drop(columns=['race_date','jockey','run_up_distance'],axis=1)\n#target=h2['run_up_distance']","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:32.994179Z","iopub.execute_input":"2022-11-14T16:46:32.994898Z","iopub.status.idle":"2022-11-14T16:46:33.003255Z","shell.execute_reply.started":"2022-11-14T16:46:32.994851Z","shell.execute_reply":"2022-11-14T16:46:33.002166Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#x_train, x_test, y_train, y_test = train_test_split(feature, target, test_size=0.2, shuffle=True)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:33.004981Z","iopub.execute_input":"2022-11-14T16:46:33.005760Z","iopub.status.idle":"2022-11-14T16:46:33.016065Z","shell.execute_reply.started":"2022-11-14T16:46:33.005712Z","shell.execute_reply":"2022-11-14T16:46:33.014925Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#scaler= StandardScaler()","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:33.017941Z","iopub.execute_input":"2022-11-14T16:46:33.019073Z","iopub.status.idle":"2022-11-14T16:46:33.029494Z","shell.execute_reply.started":"2022-11-14T16:46:33.019026Z","shell.execute_reply":"2022-11-14T16:46:33.028466Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#x_train = scaler.transform(x_train)\n#x_test = scaler.transform(x_test)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:33.031191Z","iopub.execute_input":"2022-11-14T16:46:33.032652Z","iopub.status.idle":"2022-11-14T16:46:33.042793Z","shell.execute_reply.started":"2022-11-14T16:46:33.032596Z","shell.execute_reply":"2022-11-14T16:46:33.041734Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#from sklearn.linear_model import LogisticRegression\n#model = LogisticRegression()\n#model.fit(x_train, y_train)\n#y_pred = model.predict(x_test)\n#print(y_pred)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:33.044426Z","iopub.execute_input":"2022-11-14T16:46:33.045461Z","iopub.status.idle":"2022-11-14T16:46:33.055781Z","shell.execute_reply.started":"2022-11-14T16:46:33.045423Z","shell.execute_reply":"2022-11-14T16:46:33.054568Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#accuracy_score(y_test, y_pred)","metadata":{"execution":{"iopub.status.busy":"2022-11-14T16:46:33.057579Z","iopub.execute_input":"2022-11-14T16:46:33.058285Z","iopub.status.idle":"2022-11-14T16:46:33.067913Z","shell.execute_reply.started":"2022-11-14T16:46:33.058249Z","shell.execute_reply":"2022-11-14T16:46:33.066571Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}