Skip to content

Commit 9c86d3a

Browse files
author
Yam Peleg
committed
added random classifier and random regressor
1 parent 046b1f2 commit 9c86d3a

12 files changed

Lines changed: 120 additions & 14 deletions

File tree

dist/hunga_bunga-0.1.tar.gz

6.48 KB
Binary file not shown.

example.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import random
44

5-
from hunga_bunga import HungaBungaClassifier, HungaBungaRegressor, HungaBungaZeroKnowledge
5+
from hunga_bunga import HungaBungaClassifier, HungaBungaRegressor, HungaBungaZeroKnowledge, HungaBungaRandomClassifier, HungaBungaRandomRegressor
66
from hunga_bunga.regression import gen_reg_data
77
from sklearn import datasets
88

@@ -16,22 +16,38 @@
1616

1717

1818

19-
# ---------- Classification ----------
19+
# ---------- Brute-Force Classification ----------
2020

2121
clf = HungaBungaClassifier()
2222
clf.fit(X_c, y_c)
2323
print(clf.predict(X_c))
2424

2525

2626

27-
# ---------- Regression ----------
27+
# ---------- Random Classification ----------
28+
29+
clf = HungaBungaRandomClassifier()
30+
clf.fit(X_c, y_c)
31+
print(clf.predict(X_c))
32+
33+
34+
35+
# ---------- Brute-Force Regression ----------
2836

2937
mdl = HungaBungaRegressor()
3038
mdl.fit(X_r, y_r)
3139
print(mdl.predict(X_c))
3240

3341

3442

43+
# ---------- Random Regression ----------
44+
45+
mdl = HungaBungaRandomRegressor()
46+
mdl.fit(X_r, y_r)
47+
print(mdl.predict(X_c))
48+
49+
50+
3551
# ---------- Zero Knowledge ----------
3652

3753
X, y = random.choice(((X_c, y_c), (X_r, y_r)))

hunga_bunga.egg-info/PKG-INFO

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Metadata-Version: 1.0
2+
Name: hunga-bunga
3+
Version: 0.1
4+
Summary: Brute-Force All of sklearn!
5+
Home-page: https://github.com/ypeleg/HungaBunga
6+
Author: Yam Peleg
7+
Author-email: yam@deeptrading.com
8+
License: MIT
9+
Description-Content-Type: UNKNOWN
10+
Description: Lol, why do you read this?
11+
12+
Platform: UNKNOWN

hunga_bunga.egg-info/SOURCES.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
README.txt
2+
setup.py
3+
hunga_bunga/__init__.py
4+
hunga_bunga/classification.py
5+
hunga_bunga/core.py
6+
hunga_bunga/params.py
7+
hunga_bunga/regression.py
8+
hunga_bunga.egg-info/PKG-INFO
9+
hunga_bunga.egg-info/SOURCES.txt
10+
hunga_bunga.egg-info/dependency_links.txt
11+
hunga_bunga.egg-info/requires.txt
12+
hunga_bunga.egg-info/top_level.txt
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

hunga_bunga.egg-info/requires.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
numpy

hunga_bunga.egg-info/top_level.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hunga_bunga

hunga_bunga/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
warnings.filterwarnings('ignore')
44
from multiprocessing import cpu_count
55
from sklearn.base import BaseEstimator
6-
from regression import HungaBungaRegressor
7-
from classification import HungaBungaClassifier
6+
from regression import HungaBungaRegressor, HungaBungaRandomRegressor
7+
from classification import HungaBungaClassifier, HungaBungaRandomClassifier
88

99

1010
class HungaBungaZeroKnowledge(BaseEstimator):

hunga_bunga/__init__.pyc

42 Bytes
Binary file not shown.

hunga_bunga/classification.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
import random
23
import warnings
34
warnings.filterwarnings('ignore')
45

@@ -15,6 +16,7 @@
1516
from sklearn.naive_bayes import GaussianNB
1617
from sklearn.neural_network import MLPClassifier
1718
from sklearn.tree import DecisionTreeClassifier
19+
from sklearn.model_selection import ParameterSampler
1820

1921
from sklearn.ensemble import AdaBoostRegressor, ExtraTreesRegressor, RandomForestRegressor
2022
from sklearn.tree import DecisionTreeRegressor
@@ -178,6 +180,11 @@ def run_all_classifiers(x, y, small = True, normalize_x = True, n_jobs=cpu_count
178180
all_params = (linear_models_n_params_small if small else linear_models_n_params) + (nn_models_n_params_small if small else nn_models_n_params) + ([] if small else gaussianprocess_models_n_params) + neighbor_models_n_params + (svm_models_n_params_small if small else svm_models_n_params) + (tree_models_n_params_small if small else tree_models_n_params)
179181
return main_loop(all_params, StandardScaler().fit_transform(x) if normalize_x else x, y, isClassification=True, n_jobs=n_jobs, verbose=verbose, brain=brain, test_size=test_size, n_splits=n_splits, upsample=upsample, scoring=scoring, grid_search=grid_search)
180182

183+
def run_one_classifier(x, y, small = True, normalize_x = True, n_jobs=cpu_count()-1, brain=False, test_size=0.2, n_splits=5, upsample=True, scoring=None, verbose=False, grid_search=True):
184+
all_params = (linear_models_n_params_small if small else linear_models_n_params) + (nn_models_n_params_small if small else nn_models_n_params) + ([] if small else gaussianprocess_models_n_params) + neighbor_models_n_params + (svm_models_n_params_small if small else svm_models_n_params) + (tree_models_n_params_small if small else tree_models_n_params)
185+
all_params = random.choice(all_params)
186+
return all_params[0](**(list(ParameterSampler(all_params[1], n_iter=1))[0]))
187+
181188

182189
class HungaBungaClassifier(ClassifierMixin):
183190
def __init__(self, brain=False, test_size = 0.2, n_splits = 5, random_state=None, upsample=True, scoring=None, verbose=False, normalize_x = True, n_jobs =cpu_count() - 1, grid_search=True):
@@ -202,6 +209,30 @@ def predict(self, x):
202209
return self.model.predict(x)
203210

204211

212+
class HungaBungaRandomClassifier(ClassifierMixin):
213+
def __init__(self, brain=False, test_size = 0.2, n_splits = 5, random_state=None, upsample=True, scoring=None, verbose=False, normalize_x = True, n_jobs =cpu_count() - 1, grid_search=True):
214+
self.model = None
215+
self.brain = brain
216+
self.test_size = test_size
217+
self.n_splits = n_splits
218+
self.random_state = random_state
219+
self.upsample = upsample
220+
self.scoring = None
221+
self.verbose = verbose
222+
self.n_jobs = n_jobs
223+
self.normalize_x = normalize_x
224+
self.grid_search = grid_search
225+
super(HungaBungaRandomClassifier, self).__init__()
226+
227+
def fit(self, x, y):
228+
self.model = run_one_classifier(x, y, normalize_x=self.normalize_x, test_size=self.test_size, n_splits=self.n_splits, upsample=self.upsample, scoring=self.scoring, verbose=self.verbose, brain=self.brain, n_jobs=self.n_jobs, grid_search=self.grid_search)
229+
self.model.fit(x, y)
230+
return self
231+
232+
def predict(self, x):
233+
return self.model.predict(x)
234+
235+
205236
if __name__ == '__main__':
206237
iris = datasets.load_iris()
207238
X, y = iris.data, iris.target

0 commit comments

Comments
 (0)