python


Is there a way for me to view the classes of particular instances in binary classified dataset using scikit learn


Is there a way for me to view the classes of particular instances in a binary classified dataset(classes are 0 or 1) using the scikit learn library. I have a program that performs knn on a dataset and inserts the model built into a database. I want to view instances in the the data that are classified as 0 or 1. This is the link to the dataset I am using https://drive.google.com/open?id=0B9cQtdthFqv3YVNBNk1peVltZkk
from sklearn import neighbors,datasets,preprocessing
from sklearn.cross_validation import train_test_split
import urllib.request
from sklearn.metrics import accuracy_score
import pandas as pd
import matplotlib.pyplot as plt
from sklearn import model_selection
from sklearn.metrics import precision_recall_fscore_support as score
from sklearn.externals import joblib
from sklearn.model_selection import cross_val_score
from pandas import read_csv
from sklearn.ensemble import ExtraTreesClassifier
import pandas as pd
import numpy as np
import sys
import pickle
import mysql.connector as mc
def doSupervised(username,fileid,filename):
try:
connection = mc.connect (host = "localhost",
user = "**",
passwd = "**",
db = "**")
except mc.Error as e:
print("Error %d: %s" % (e.args[0], e.args[1]))
sys.exit(1)
cursor = connection.cursor()
# load data
dataframe = pd.DataFrame.from_csv(filename)
X= np.array(dataframe)
y = np.array(dataframe['Class'])
# fit an Extra Trees model to the data
model = ExtraTreesClassifier()
model.fit_transform(X, y)
# display the relative importance of each attribute
#print(model.feature_importances_)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
clf = neighbors.KNeighborsClassifier(algorithm='auto')
#fit the data to the model
clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)
#print (y_pred)
algorithmType="Supervised"
accuracy =accuracy_score(y_test, y_pred )
print(accuracy)
#save classifier to a file
name="supervisedmodel.pkl"
data = joblib.dump(clf, name)
#name = 'supervisedmodel.sav'
#data = pickle.dump(clf, open(name, 'wb'))
sql_command = "INSERT INTO machinelearningmodel (username, fileID,
name,data,accuracy,algorithmType ) VALUES (%s, %s, %s, %s, %s, %s)",
(username, str(fileid), name, str(data), str(accuracy),algorithmType)
cursor.execute(*sql_command)
#print(sql_command)
cursor.close()
connection.commit()
connection.close()
if __name__ == "__main__":
doSupervised(sys.argv[1],sys.argv[2],sys.argv[3])


Related Links

Decoding NumPy int64 binary representation
Groupby DataFram by its rank/percentile
AttributeError: 'str' object has no attribute 'loads', json.loads()
Can anyone explain me the example of an exploit in Python’s pickle module?
Why does pandas multi-index dataframe slicing seem inconsistent?
How to restore a tensorflow network and to use it
Python swampy installation error
How to save a csv file so iPython shell can open and use it?
Combine tuples of tuples if share some elements
Inheritance in Python: What's wrong with my code?
Confusing reference ownership: how to properly deallocate (via Py_DECREF) objects of an object?
Insert element to list based on previous and next elements
Why is str.strip() so much faster than str.strip(' ')?
How to make nosetests use dotted syntax?
Slice column in panda database and averaging results
How to implement cumulative distribution function using interval alpha, beta and X in Python?

Categories

HOME
google-apps-script
fparsec
reportportal
thunderbird-addon
memory-leaks
matplotlib
ext.net
spring-cloud-contract
dropbox
hashicorp-vault
dryioc
tee
gwtp
symfony-forms
equalizer
eclipse-luna
scenebuilder
python-unicode
eclipselink
propel2
styles
ng2-dragula
plsqldeveloper
raphael
countif
delete-file
sumo
hash-collision
owl-api
gzip
vertex-buffer
xor
spring-profiles
exponential
construct-2
rhomobile
geomesa
readfile
haskell-pipes
ntfs-mft
delphi-10.1-berlin
intellilock
ddms
xbim
react-native-router-flux
finite-element-analysis
scalafx
php-ews
estimation
azure-availability-set
floor
proof
tuleap
uiviewpropertyanimator
jenkins-jira-trigger
persistent
text-classification
heroku-postgres
visual-studio-templates
ruby-2.0
children
json-schema-validator
mercurial-hook
coordinate-transformation
brackets-shell
magento-1.4
spservices
cctray
loose-typing
self-hosting
getrusage
code-readability
evo
rad
bridge
google-hadoop
guzzle6
es2015
moai
rhel5
named-ranges
cocoascript
dmp
log4cplus
sgml
sanitization
layered
image-zoom
dllexport
cgimageref
shiva3d
fraud-prevention
mozart-mvc
attachevent
xgettext
icefaces-3
subtract
windows-phone-7-emulator
viewdidload
coff
easygui
port-scanning
open-graph-beta
osx-leopard
revert
openwysiwyg
internals





Mobile Apps Dev
Database Users
javascript
java
csharp
php
android


MS Developer
developer works
python
ios
c
html
jquery


RDBMS discuss