-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
66 lines (55 loc) · 2.02 KB
/
script.py
File metadata and controls
66 lines (55 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# STEPS
# get the data from csv file
# get the features and labels
# do the processing
# split the training and test data set
# define a classifier
# get the score
class DataProcessing:
def __init__(self, filePath):
self.csv_file_path = filePath
self.data_frame = None
self.features = None
self.labels = None
self.X_train = None
self.Y_train = None
self.X_test = None
self.Y_test = None
# get the data from csv file
def get_data_from_csv(self):
import pandas
self.data_frame = pandas.read_csv(self.csv_file_path)
# get the features and labels
def get_features_and_labels(self):
import numpy
self.labels = numpy.array(self.data_frame['label'])
self.features = numpy.array(self.data_frame.drop(['label'], 1))
# scaling the values propotionally
def do_scaling(self):
from sklearn.preprocessing import scale
scale(self.features)
# split the training and test data set
def split_train_and_test_data(self):
from sklearn.model_selection import train_test_split
self.X_train, self.X_test, self.Y_train, self.Y_test = train_test_split(self.features, self.label, test.size = 0.3)
class ClassificationAlgorithms:
def __init__(self):
self.classifier = None
# define a classifier
def get_classifier(self, classifier_type, X_train, Y_train):
if(classifier_type == 'knn'):
from sklearn import neighbors
self.classifier = neighbors.kneighbors.classifier().fit(X_train, Y_train)
# get the score
def get_score(self, X_test, Y_test):
print(self.classifier.score(X_test, Y_test))
def main():
dp = DataProcessing('enterCSVFilePathHere')
dp.get_data_from_csv
dp.get_features_and_labels
dp.do_scaling
dp.split_train_and_test_data
ClassificationObject = ClassificationAlgorithms()
ClassificationObject.get_classifier('knn', dp.X_train, dp.Y_train)
ClassificationObject.get_score(dp.X_test, dp.Y_test)
main()