Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" precision recall f1-score support\n",
"\n",
" 0 0.93 0.99 0.96 10619\n",
" 1 0.05 0.01 0.01 811\n",
"\n",
"avg / total 0.87 0.92 0.89 11430\n",
"\n",
"[[10505 114]\n",
" [ 805 6]]\n"
]
},
{
"data": {
"text/plain": [
"array([ 0.92882405, 0.05 ])"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"#import pandas.DataFrame as df\n",
"import numpy as np\n",
"from sklearn.metrics import precision_score\n",
"from sklearn.linear_model import LogisticRegression\n",
"from sklearn.metrics import confusion_matrix, classification_report\n",
"from sklearn.preprocessing import StandardScaler, LabelEncoder\n",
"from sklearn.model_selection import train_test_split, GridSearchCV, cross_val_score\n",
"%matplotlib inline\n",
"\n",
"thief = pd.read_csv(\"C:\\Criminal\\criminal_train_2.csv\")\n",
"\n",
"y = thief['Criminal']\n",
"X = thief.drop('Criminal', axis = 1)\n",
"\n",
"#X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 42)\n",
"thief_test=pd.read_csv(\"C:\\Criminal\\criminal_test.csv\")\n",
"\n",
"sc = StandardScaler()\n",
"X = sc.fit_transform(X)\n",
"thief_test = sc.fit_transform(thief_test)\n",
"\n",
"rfc = LogisticRegression(C=0.001)\n",
"rfc.fit(X, y)\n",
"pred_rfc = rfc.predict(thief_test)\n",
"\n",
"y_new=pd.DataFrame(y)\n",
"y_new = y_new[:11430]\n",
"\n",
"print(classification_report(y_new, pred_rfc))\n",
"\n",
"print(confusion_matrix(y_new, pred_rfc))\n",
"\n",
"precision_score(y_new,pred_rfc,average=None)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

# coding: utf-8

# In[13]:


import pandas as pd
#import pandas.DataFrame as df
import numpy as np
from sklearn.metrics import precision_score
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import confusion_matrix, classification_report
from sklearn.preprocessing import StandardScaler, LabelEncoder
from sklearn.model_selection import train_test_split, GridSearchCV, cross_val_score
get_ipython().run_line_magic('matplotlib', 'inline')

thief = pd.read_csv("C:\Criminal\criminal_train_2.csv") #load .csv file to train the model
thief_test=pd.read_csv("C:\Criminal\criminal_test.csv")#load .csv file to test the model

y = thief['Criminal']
X = thief.drop('Criminal', axis = 1)

#X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 42)

sc = StandardScaler()
X = sc.fit_transform(X)
thief_test = sc.fit_transform(thief_test)

rfc = LogisticRegression(C=0.001)
rfc.fit(X, y)
pred_rfc = rfc.predict(thief_test)

y_new=pd.DataFrame(y)
y_new = y_new[:11430]

print(classification_report(y_new, pred_rfc))

print(confusion_matrix(y_new, pred_rfc))# to determine the accuracy of the model

precision_score(y_new,pred_rfc,average=None)

Loading