Skip to content

Instantly share code, notes, and snippets.

@mirsahib
Created March 22, 2020 05:09
Show Gist options
  • Select an option

  • Save mirsahib/450b6868eea6da4c1aebdfe39f6d3f79 to your computer and use it in GitHub Desktop.

Select an option

Save mirsahib/450b6868eea6da4c1aebdfe39f6d3f79 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "7cz67itTa-JM"
},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"from sklearn.model_selection import train_test_split\n",
"from sklearn.model_selection import KFold\n",
"from sklearn.ensemble import RandomForestClassifier\n",
"from sklearn.metrics import accuracy_score,roc_auc_score"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "NG3_PkJ3a-JZ"
},
"outputs": [],
"source": [
"dataset = pd.read_csv('Joint_Dataset.csv')\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "Ph4R0LRma-Jh"
},
"outputs": [],
"source": [
"X = dataset.drop('label',axis=1)\n",
"y = dataset['label']"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 187
},
"colab_type": "code",
"id": "yrx1_8g_a-Jo",
"outputId": "72fd7dbe-c32e-4faa-f4d6-9d0b96005de9"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"95.26315789473684\n",
"94.56140350877193\n",
"94.34210526315789\n",
"95.13157894736842\n",
"95.6140350877193\n",
"94.82456140350877\n",
"94.16666666666667\n",
"94.33962264150944\n",
"95.17332163229487\n",
"95.08556384379114\n"
]
}
],
"source": [
"import pdb\n",
"Kfold = KFold(10,True,1)\n",
"for train_idx,test_idx in Kfold.split(dataset):\n",
" X_train,X_test,y_train,y_test = X.iloc[train_idx],X.iloc[test_idx],y.iloc[train_idx],y.iloc[test_idx]\n",
" clf = RandomForestClassifier(n_estimators=100, random_state=0, n_jobs=-1)\n",
" clf.fit(X_train,y_train)\n",
" output = clf.predict(X_test)\n",
" accuracy = accuracy_score(y_test,output)*100\n",
" print(accuracy)\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "XhQO7VCxa-Jz"
},
"outputs": [],
"source": []
}
],
"metadata": {
"colab": {
"name": "Machine_learning_raw_data.ipynb",
"provenance": [],
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment