Skip to content

Instantly share code, notes, and snippets.

@jimmyverdoora
Last active October 24, 2021 16:33
Show Gist options
  • Save jimmyverdoora/e2a7170347114dde143e8c1c3e6e316d to your computer and use it in GitHub Desktop.
Save jimmyverdoora/e2a7170347114dde143e8c1c3e6e316d to your computer and use it in GitHub Desktop.
bg padova
import numpy as np
from sklearn.ensemble import RandomForestRegressor
# cleaned data as np array (training vectors don't contain targets
targets1 = np.loadtxt('targets1.csv', delimiter=',')
targets2 = np.loadtxt('targets2.csv', delimiter=',')
targets3 = np.loadtxt('targets3.csv', delimiter=',')
targets4 = np.loadtxt('targets4.csv', delimiter=',')
training1 = np.loadtxt('training1.csv', delimiter=',')
training2 = np.loadtxt('training2.csv', delimiter=',')
training3 = np.loadtxt('training3.csv', delimiter=',')
training4 = np.loadtxt('training4.csv', delimiter=',')
vali = np.loadtxt('vali.csv', delimiter=',')
classi = []
score = []
for i in (1,2,3,4):
xtrain, ytrain = eval('training%d, targets%d' % (i, i))
classi.append(RandomForestRegressor(n_estimators=200, verbose=0, n_jobs=6))
classi[-1].fit(xtrain, ytrain)
print("done")
vali_split = [[],[],[],[]]
index_split = [[],[],[],[]]
for ind, row in enumerate(vali):
vali_split[int(row[0]) - 1].append(row)
index_split[int(row[0]) - 1].append(ind)
def launch_pred(frac):
predictions = np.zeros((vali.shape[0],))
for i in (1,2,3,4):
tmp_pred_split = classi[i - 1].predict(np.array(vali_split[i - 1]))
for index, pred in enumerate(tmp_pred_split):
predictions[index_split[i - 1][index]] = pred
print(i)
index = 0
while index < predictions.shape[0]:
if vali[index][2] == 1.0:
if index > 0:
# build new predictions based on the last frac of data for each id:
somma = 0
tmp_index = index - 1
killer = numero * frac
while index - tmp_index + 1 < killer:
somma += predictions[tmp_index]
tmp_index = tmp_index - 1
n = (2 * somma + killer ** 2 - killer) / (2 * killer) - killer + numero
if n < numero - 0.5:
n = numero - 0.5
tmp_index = index - numero
print(index)
while True:
predictions[tmp_index] = n
n = n - 1
tmp_index = tmp_index + 1
if vali[tmp_index][2] == 1.0:
break
# ---
numero = 1
else:
numero += 1
index += 1
np.savetxt("predictions.csv", predictions)
launch_pred(0.1)
import ipdb
ipdb.set_trace()
@0x07CB
Copy link

0x07CB commented Oct 24, 2021

What that do , please write more comments in your source-code…. 🥱

I really want understand you, I have read parts of repository’s from your git and I ask to U just that:

Why you write an machine learning code, that it’s interest or just publication of result to exercice from an stude for school or also it’s an activity of your free-time ?

You are at the begin of programming practice or U have just an sequential vision of the code you type…. ???
I Can type an document with this contents: 😃

  • advice and more the conventionnals rules
  • Object Oriented Programmings basic’s
  • The mistakes if you type an cipher algorithm code *** (espcially on the part related with the pseudo-random numbers generator) ***
  • …. Etc…

So…
I have so many question just I don’t want know U, a lot of coder’s on that don’t write an user readme, my account it’s for the historical share of all projects I start and want done at the end of this human life I have… 🛩️ So I explore git it’s better for get a lot of free new code,ideas,parts,subs,librabry…. to made my pheonetic-based of an offline Vocal Assistant … My ML/DL research subject I have found today…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment