-
Notifications
You must be signed in to change notification settings - Fork 0
/
avgWeights.py
30 lines (22 loc) · 1.08 KB
/
avgWeights.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
#__________________IMPORTS_________________________________________________________
import pandas as pd
import numpy as np
#__________________MAIN_________________________________________________________
#read coefficients from logistic regression model
weights = pd.read_csv("LogRegCoef.csv", header=None).to_numpy() #k by m array where k is the number of classes and m is the number of features
#read the list of n-grams used by the logistic regression model
feats = pd.read_csv("FinalFeatureSetLogReg.csv", header=None).to_numpy()
#average the coeficients across 9 classifiers and save the largest 15 coeficients
absWeights = np.absolute(weights)
avgWeights = np.mean(absWeights, axis=0)
max = np.argsort(avgWeights)
max = max[-15:]
with open("AvgCoefMax15.csv", "w") as fp:
for a in max:
fp.write(str(avgWeights[a])+","+str(feats[a][0])+"\n")
#save the largest 15 coeficients for the classifier for class 3
max = np.argsort(weights[2])
max = max[-15:]
with open("Class3CoefMax15.csv", "w") as fp:
for a in max:
fp.write(str(weights[2][a])+","+str(feats[a][0])+"\n")