-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated with latest versions of scripts and other files
- Loading branch information
1 parent
7a7ffd6
commit 8500b1a
Showing
16 changed files
with
18,195 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
from keras.models import Sequential | ||
from keras.layers import Dense | ||
from keras.callbacks import CSVLogger | ||
from keras.utils import np_utils | ||
from keras import optimizers | ||
from keras import layers | ||
from keras.models import load_model | ||
import numpy | ||
import pandas as pd | ||
import os | ||
|
||
|
||
if os.path.exists("history.csv"): | ||
os.remove("history.csv")#delete old history file | ||
|
||
|
||
# fix random seed for reproducibility | ||
numpy.random.seed(7) | ||
|
||
# Defining column names for dataset | ||
X_COLUMN_NAMES = ['APM','SelectByHotkeys','AssignToHotkeys','UniqueHotkeys','MinimapAttacks','MinimapRightClicks','NumberOfPACs','GapBetweenPACs','ActionLatency','ActionsInPAC','TotalMapExplored','WorkersMade','UniqueUnitsMade','ComplexUnitsMade','ComplexAbilitiesUsed'] | ||
Y_COLUMN_NAMES = ['LeagueIndex'] | ||
|
||
# Import training dataset | ||
#training_dataset_X = pd.read_csv('SkillCraft1_Dataset_modified.csv', names=X_COLUMN_NAMES, header=None)#using whole dataset forcross validation | ||
training_dataset_X = pd.read_csv('trainX.csv', names=X_COLUMN_NAMES, header=None) | ||
print(training_dataset_X.head()) | ||
|
||
train_x = training_dataset_X.iloc[:,:].values | ||
|
||
|
||
|
||
training_dataset_Y = pd.read_csv('trainY.csv', names=Y_COLUMN_NAMES, header=None) | ||
training_dataset_Y.loc[:,'LeagueIndex'] = training_dataset_Y.loc[:,'LeagueIndex'] - 1; | ||
print("First rows of Training dataset Y: \n\n",training_dataset_Y.head(),"\n*********************************\n") | ||
print("Training Dataset Y summary: \n\n",training_dataset_Y.describe(),"\n*********************************\n") | ||
|
||
|
||
train_y = training_dataset_Y.iloc[:,:].values | ||
|
||
# Encoding training dataset | ||
encoding_train_y = np_utils.to_categorical(train_y) | ||
|
||
# Import testing dataset | ||
test_dataset_X = pd.read_csv('testX.csv', names=X_COLUMN_NAMES, header=None) | ||
test_x = test_dataset_X.iloc[:, :].values | ||
|
||
test_dataset_Y = pd.read_csv('testY.csv', names=Y_COLUMN_NAMES, header=None) | ||
test_dataset_Y.loc[:,'LeagueIndex'] = test_dataset_Y.loc[:,'LeagueIndex'] - 1; | ||
|
||
test_y = test_dataset_Y.iloc[:, :].values | ||
|
||
# Encoding training dataset | ||
encoding_test_y = np_utils.to_categorical(test_y) | ||
|
||
activation = layers.LeakyReLU(alpha=0.2) | ||
|
||
# Creating a model | ||
model = Sequential() | ||
model.add(Dense(15, input_dim=15)) | ||
model.add(Dense(35, activation='sigmoid')) | ||
#model.add(Dense(1, activation='sigmoid')) | ||
model.add(Dense(8, activation='softmax')) # when league indices have been converted to 0-7 instead of 1-8 | ||
#model.add(Dense(9, activation='softmax')) | ||
#model.add(Dense(1, activation='linear')) #for non-softmax andnon-encoded to categorical | ||
|
||
print(model.summary()) | ||
|
||
|
||
#Choosing optimizer | ||
sgdOptimizer = optimizers.SGD(lr=0.0025, momentum=0.2, decay=0.0, nesterov=False) | ||
|
||
# Compiling model | ||
#model.compile(loss='categorical_crossentropy', optimizer = sgdOptimizer, metrics=['accuracy']) | ||
model.compile(loss='categorical_crossentropy', optimizer = 'adam', metrics=['accuracy']) | ||
|
||
csv_logger = CSVLogger('history.csv', append=True, separator=',') | ||
|
||
# Training a model | ||
history = model.fit(train_x, encoding_train_y, epochs=100, batch_size=60, validation_split = 0.25,callbacks=[csv_logger]) | ||
|
||
model.save('arslan.h5'); | ||
|
||
#model.fit(train_x, train_y, epochs=50, batch_size=10) | ||
|
||
fileModel = load_model('arslan.h5'); | ||
|
||
# evaluate the model | ||
scores = fileModel.evaluate(test_x, encoding_test_y) | ||
#scores = model.evaluate(test_x, test_y) | ||
|
||
print("\nAccuracy: %.2f%%" % (scores[1]*100)) | ||
|
||
#model_predictions = fileModel.predict(test_x); | ||
|
||
#print("\n\n",model_predictions[0:5]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
from keras.models import Sequential | ||
from keras.layers import Dense | ||
from keras.callbacks import CSVLogger | ||
from keras.utils import np_utils | ||
from keras import optimizers | ||
from keras import layers | ||
from sklearn.cross_validation import StratifiedKFold | ||
import numpy | ||
import pandas as pd | ||
import os | ||
|
||
|
||
|
||
|
||
#missing values are question marks in this data set | ||
missingValues = ["?"] | ||
|
||
#read csv into dataframe | ||
df = pd.read_csv("SkillCraft1_Dataset_modified.csv", na_values = missingValues) | ||
|
||
df.loc[:,'LeagueIndex'] = df.loc[:,'LeagueIndex'] - 1; | ||
|
||
# fix random seed for reproducibility | ||
numpy.random.seed(7) | ||
|
||
# Defining column names for dataset | ||
X_COLUMN_NAMES = ['APM','SelectByHotkeys','AssignToHotkeys','UniqueHotkeys','MinimapAttacks','MinimapRightClicks','NumberOfPACs','GapBetweenPACs','ActionLatency','ActionsInPAC','TotalMapExplored','WorkersMade','UniqueUnitsMade','ComplexUnitsMade','ComplexAbilitiesUsed'] | ||
Y_COLUMN_NAMES = ['LeagueIndex'] | ||
|
||
|
||
total_x = df.iloc[:,1:16].values | ||
total_y = df.iloc[:,0].values | ||
|
||
print(total_y) | ||
#print(total_x) | ||
|
||
|
||
n_folds = 10 | ||
#skf = StratifiedKFold(n_splits=n_folds) | ||
#skf.get_n_splits(total_x, total_y) | ||
|
||
labels = [0,1,2,3,4,5,6,7] | ||
|
||
skf = StratifiedKFold(total_y, n_folds=n_folds, shuffle=True) | ||
|
||
sumOfAccs = 0; | ||
|
||
for i, (train, test) in enumerate(skf): | ||
|
||
train_x = total_x[train] | ||
test_x = total_x[test] | ||
|
||
# Encoding training dataset | ||
encoding_train_y = np_utils.to_categorical(total_y[train]) | ||
|
||
# Encoding training dataset | ||
encoding_test_y = np_utils.to_categorical(total_y[test]) | ||
|
||
activation = layers.LeakyReLU(alpha=0.2) | ||
|
||
# Creating a model | ||
model = Sequential() | ||
model.add(Dense(15, input_dim=15)) | ||
model.add(Dense(35, activation='sigmoid')) | ||
#model.add(Dense(1, activation='sigmoid')) | ||
model.add(Dense(8, activation='softmax')) # when league indices have been converted to 0-7 instead of 1-8 | ||
#model.add(Dense(9, activation='softmax')) | ||
#model.add(Dense(1, activation='linear')) #for non-softmax andnon-encoded to categorical | ||
|
||
|
||
|
||
print(model.summary()) | ||
|
||
|
||
#Choosing optimizer | ||
sgdOptimizer = optimizers.SGD(lr=0.0025, momentum=0.2, decay=0.0, nesterov=False) | ||
|
||
# Compiling model | ||
#model.compile(loss='categorical_crossentropy', optimizer = sgdOptimizer, metrics=['accuracy']) | ||
model.compile(loss='categorical_crossentropy', optimizer = 'adam', metrics=['accuracy']) | ||
|
||
csv_logger = CSVLogger('history' + str(i) + '.csv', append=True, separator=',') | ||
|
||
# Training a model | ||
history = model.fit(train_x, encoding_train_y, epochs=100, batch_size=60, validation_split = 0.25,callbacks=[csv_logger]) | ||
|
||
|
||
#model.fit(train_x, train_y, epochs=50, batch_size=10) | ||
|
||
# evaluate the model | ||
scores = model.evaluate(test_x, encoding_test_y) | ||
#scores = model.evaluate(test_x, test_y) | ||
|
||
sumOfAccs += scores[1]; | ||
|
||
print("\nAccuracy: %.2f%%" % (scores[1]*100)) | ||
|
||
|
||
print("\nAccuracy overall: %.2f%%" % ((sumOfAccs / n_folds)*100)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
from keras.models import Sequential | ||
from keras.layers import Dense | ||
from keras.callbacks import CSVLogger | ||
from keras.utils import np_utils | ||
from keras import optimizers | ||
from keras import layers | ||
import numpy | ||
import pandas as pd | ||
import os | ||
|
||
if os.path.exists("history.csv"): | ||
os.remove("history.csv")#delete old history file | ||
|
||
# fix random seed for reproducibility | ||
numpy.random.seed(7) | ||
|
||
# Defining column names for dataset | ||
X_COLUMN_NAMES = ['APM','SelectByHotkeys','AssignToHotkeys','UniqueHotkeys','MinimapAttacks','MinimapRightClicks','NumberOfPACs','GapBetweenPACs','ActionLatency','ActionsInPAC','TotalMapExplored','WorkersMade','UniqueUnitsMade','ComplexUnitsMade','ComplexAbilitiesUsed'] | ||
Y_COLUMN_NAMES = ['LeagueIndex'] | ||
|
||
# Import training dataset | ||
#training_dataset_X = pd.read_csv('SkillCraft1_Dataset_modified.csv', names=X_COLUMN_NAMES, header=None)#using whole dataset forcross validation | ||
training_dataset_X = pd.read_csv('trainX.csv', names=X_COLUMN_NAMES, header=None) | ||
print(training_dataset_X.head()) | ||
|
||
train_x = training_dataset_X.iloc[:,:].values | ||
|
||
|
||
|
||
training_dataset_Y = pd.read_csv('trainY.csv', names=Y_COLUMN_NAMES, header=None) | ||
training_dataset_Y.loc[:,'LeagueIndex'] = training_dataset_Y.loc[:,'LeagueIndex'] - 1; | ||
training_dataset_Y.loc[training_dataset_Y['LeagueIndex'] == 1,'LeagueIndex'] = 0; # map (0,1) to 0 | ||
training_dataset_Y.loc[training_dataset_Y['LeagueIndex'] == 2,'LeagueIndex'] = 1; # map (2,3) to 1 | ||
training_dataset_Y.loc[training_dataset_Y['LeagueIndex'] == 3,'LeagueIndex'] = 1; # map (2,3) to 1 | ||
training_dataset_Y.loc[training_dataset_Y['LeagueIndex'] == 4,'LeagueIndex'] = 2; # map (4,5) to 2 | ||
training_dataset_Y.loc[training_dataset_Y['LeagueIndex'] == 5,'LeagueIndex'] = 2; # map (4,5) to 2 | ||
training_dataset_Y.loc[training_dataset_Y['LeagueIndex'] == 6,'LeagueIndex'] = 3; # map (6,7) to 3 | ||
training_dataset_Y.loc[training_dataset_Y['LeagueIndex'] == 7,'LeagueIndex'] = 3; # map (6,7) to 3 | ||
print("First rows of Training dataset Y: \n\n",training_dataset_Y.head(),"\n*********************************\n") | ||
print("Training Dataset Y summary: \n\n",training_dataset_Y.describe(),"\n*********************************\n") | ||
|
||
|
||
train_y = training_dataset_Y.iloc[:,:].values | ||
|
||
# Encoding training dataset | ||
encoding_train_y = np_utils.to_categorical(train_y) | ||
|
||
# Import testing dataset | ||
test_dataset_X = pd.read_csv('testX.csv', names=X_COLUMN_NAMES, header=None) | ||
test_x = test_dataset_X.iloc[:, :].values | ||
|
||
test_dataset_Y = pd.read_csv('testY.csv', names=Y_COLUMN_NAMES, header=None) | ||
test_dataset_Y.loc[:,'LeagueIndex'] = test_dataset_Y.loc[:,'LeagueIndex'] - 1; | ||
test_dataset_Y.loc[test_dataset_Y['LeagueIndex'] == 1,'LeagueIndex'] = 0; # map (0,1) to 0 | ||
test_dataset_Y.loc[test_dataset_Y['LeagueIndex'] == 2,'LeagueIndex'] = 1; # map (2,3) to 1 | ||
test_dataset_Y.loc[test_dataset_Y['LeagueIndex'] == 3,'LeagueIndex'] = 1; # map (2,3) to 1 | ||
test_dataset_Y.loc[test_dataset_Y['LeagueIndex'] == 4,'LeagueIndex'] = 2; # map (4,5) to 2 | ||
test_dataset_Y.loc[test_dataset_Y['LeagueIndex'] == 5,'LeagueIndex'] = 2; # map (4,5) to 2 | ||
test_dataset_Y.loc[test_dataset_Y['LeagueIndex'] == 6,'LeagueIndex'] = 3; # map (6,7) to 3 | ||
test_dataset_Y.loc[test_dataset_Y['LeagueIndex'] == 7,'LeagueIndex'] = 3; # map (6,7) to 3 | ||
|
||
|
||
test_y = test_dataset_Y.iloc[:, :].values | ||
|
||
# Encoding training dataset | ||
encoding_test_y = np_utils.to_categorical(test_y) | ||
|
||
activation = layers.LeakyReLU(alpha=0.2) | ||
|
||
# Creating a model | ||
model = Sequential() | ||
model.add(Dense(15, input_dim=15)) | ||
model.add(Dense(35, activation='sigmoid')) | ||
#model.add(Dense(1, activation='sigmoid')) | ||
model.add(Dense(4, activation='softmax')) # when league indices have been converted to 0-3 instead of 1-8 | ||
#model.add(Dense(9, activation='softmax')) | ||
#model.add(Dense(1, activation='linear')) #for non-softmax andnon-encoded to categorical | ||
|
||
print(model.summary()) | ||
|
||
|
||
#Choosing optimizer | ||
sgdOptimizer = optimizers.SGD(lr=0.0025, momentum=0.25, decay=0.0, nesterov=False) | ||
|
||
# Compiling model | ||
#model.compile(loss='categorical_crossentropy', optimizer = sgdOptimizer, metrics=['accuracy']) | ||
model.compile(loss='categorical_crossentropy', optimizer = 'adam', metrics=['accuracy']) | ||
|
||
csv_logger = CSVLogger('history.csv', append=True, separator=',') | ||
|
||
# Training a model | ||
history = model.fit(train_x, encoding_train_y, epochs=100, batch_size=40, validation_split = 0.25,callbacks=[csv_logger]) | ||
|
||
|
||
#model.fit(train_x, train_y, epochs=50, batch_size=10) | ||
|
||
# evaluate the model | ||
scores = model.evaluate(test_x, encoding_test_y) | ||
#scores = model.evaluate(test_x, test_y) | ||
|
||
print("\nAccuracy: %.2f%%" % (scores[1]*100)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import pandas as pd | ||
import numpy as np | ||
import sklearn | ||
import matplotlib.pyplot as plt | ||
from sklearn.linear_model import LinearRegression | ||
from sklearn.model_selection import train_test_split | ||
|
||
|
||
|
||
|
||
#missing values are question marks in this data set | ||
missingValues = ["?"] | ||
|
||
#read csv into dataframe | ||
df = pd.read_csv("SkillCraft1_Dataset_modified.csv", na_values = missingValues) | ||
|
||
print("*****************************************\nCorrelation coefficients: \n") | ||
|
||
print(df.corr()) | ||
|
||
|
||
print("****************************************\n") | ||
|
||
print(list(df)) | ||
|
||
print("****************************************\n") | ||
|
||
print("Getting X and Y arrays...") | ||
|
||
X = df[['APM','SelectByHotkeys','AssignToHotkeys','UniqueHotkeys','MinimapAttacks','MinimapRightClicks','NumberOfPACs','GapBetweenPACs','ActionLatency','ActionsInPAC','TotalMapExplored','WorkersMade','UniqueUnitsMade','ComplexUnitsMade','ComplexAbilitiesUsed']] | ||
|
||
Y = df['LeagueIndex'] | ||
|
||
print("Splitting into Training and Testing arrays....") | ||
|
||
trainX , testX , trainY, testY = train_test_split(X , Y , test_size=0.2) | ||
|
||
print("Outputting trainging and testing datasets to files...") | ||
|
||
with open('trainX.csv', 'w') as FOUT: | ||
np.savetxt(FOUT, trainX, delimiter = ',') | ||
|
||
with open('testX.csv', 'w') as FOUT: | ||
np.savetxt(FOUT, testX, delimiter = ',') | ||
|
||
with open('trainY.csv', 'w') as FOUT: | ||
np.savetxt(FOUT, trainY, delimiter = ',') | ||
|
||
with open('testY.csv', 'w') as FOUT: | ||
np.savetxt(FOUT, testY, delimiter = ',') | ||
|
||
print("Creating and Training model...") | ||
|
||
lm = LinearRegression() | ||
|
||
model = lm.fit(trainX , trainY) | ||
|
||
|
||
print("Visualizing predictions...") | ||
|
||
predictions = lm.predict(testX) | ||
|
||
with open('predictionsMLR.txt', 'w') as FOUT: | ||
np.savetxt(FOUT, predictions,delimiter = ',') | ||
|
||
plt.scatter(testY,predictions) | ||
|
||
|
||
|
||
print("Score: ", model.score(testX, testY)) | ||
|
||
plt.title('SkillCraft1 Multiple Linear Regression Predictions') | ||
plt.xlabel('Expected LeagueIndex') | ||
plt.ylabel('Predicted LeagueIndex') | ||
plt.show() | ||
|
||
|
Oops, something went wrong.