-
Notifications
You must be signed in to change notification settings - Fork 0
/
RandomForestC1.py
115 lines (100 loc) · 2.28 KB
/
RandomForestC1.py
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
'''
Created on 21-Aug-2014
@author: lokesh
'''
#! /usr/bin/env python
from infos import COL_VARS
from infos import filein1
from infos import fileout1
from scipy import optimize
import pylab as P
import math
import matplotlib.pyplot as plt
from pandas import read_csv
import numpy
from sklearn.ensemble import RandomForestClassifier
from sklearn import linear_model
A = read_csv(filein1)
print type(A)
A = A.values
X = A[:, 2:COL_VARS + 2]
Y = A[:, COL_VARS + 2]
for j in range(0, COL_VARS):
array1 = []
for i in range (0, len(X)):
if math.isnan(X[i][j]) is False :
array1.append(X[i][j])
value = numpy.mean(array1)
for i in range (0, len(X)):
if(math.isnan(X[i][j])):
X[i][j] = -1
print len(X)
X= X.T
for i in range(0, len(X)):
#for j in range (0, len(X[i])):
# X[i][j] = int(X[i][j])
plt.plot(X[i],linewidth=0.1)
plt.savefig(`i` + '.png',dpi=800)
plt.clf()
# print type(X)
#
# print COL_VARS
# # X.append()
#
# # print X
#
# # print type( X[0][0] )
# # sum2 = 0.0
# # print type( sum2 )
# # print sum2+X[0][0]
#
#
#
# for j in range(0, COL_VARS):
# array1 = []
# for i in range (0, len(X)):
# if math.isnan(X[i][j]) is False :
# array1.append(X[i][j])
#
# value = numpy.mean(array1)
# for i in range (0, len(X)):
# if(math.isnan(X[i][j])):
# X[i][j] = value
#
#
#
# test = read_csv(fileout1)
# test = test.values
# test = test[:, 2:COL_VARS + 2]
#
#
# for j in range(0, COL_VARS):
# array1 = []
# for i in range (0, len(test)):
# if math.isnan(test[i][j]) is False :
# array1.append(test[i][j])
# value = numpy.mean(array1)
# for i in range (0, len(test)):
# if(math.isnan(test[i][j])):
# test[i][j] = value
#
# # clf= optimize.brent()
# clf = RandomForestClassifier(n_estimators=20)
# # clf = linear_model.LinearRegression()
#
# clf = clf.fit(X, Y)
#
# result = clf.predict(test)
#
#
# f = open("files/crim1.csv", "w")
# f.write("title\n")
#
#
# for i in range(0, len(result)):
# f.write("%d\n" % result[i])
#
#
# # numpy.savetxt("files/crim2.csv",result, fmt ="%f")
# f.close()
print "sucess!!"