mcasl / pipegraph Goto Github PK
View Code? Open in Web Editor NEWHome of the PipeGraph extension to Scikit-Learn
License: Other
Home of the PipeGraph extension to Scikit-Learn
License: Other
Traceback (most recent call last):
File "scripts/train_regressor.py", line 199, in
main(args)
File "scripts/train_regressor.py", line 106, in main
model.fit(features_train, scores_train)
File "/Users/orestis/.local/share/virtualenvs/-HnoKq6z_/lib/python3.7/site-packages/pipegraph/base.py", line 184, in fit
self.fit_graph = build_graph(self.fit_connections)
File "/Users/orestis/.local/share/virtualenvs/-HnoKq6z/lib/python3.7/site-packages/pipegraph/base.py", line 497, in build_graph
current_node = graph.node[name]
AttributeError: 'DiGraph' object has no attribute 'node'
Minimal Example:
from pipegraph.base import PipeGraph
X_ = np.arange(30).reshape(15,2)
y_ = np.arange(15)
print(f'X, y shape: {X_.shape}, {y_.shape}')
svr_rbf = SVR(kernel='rbf', C=100, gamma=0.1, epsilon=.1)
steps = [('svr', svr_rbf)]
pgraph = PipeGraph(steps=steps)
pgraph.fit(X_, y_)
print(f'predicted shape: {pgraph.predict(X_).shape}')
Results in
X, y shape: (15, 2), (15,)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-98-dcba51e79001> in <module>
18 steps = [('svr', svr_rbf)]
19 pgraph = PipeGraph(steps=steps)
---> 20 pgraph.fit(X_, y_)
21 print(f'predicted shape: {pgraph.predict(X_).shape}')
22
~/Projects/korean-ml/venv/lib/python3.9/site-packages/pipegraph/base.py in fit(self, X, y, **kwargs)
182 self.fit_connections = make_connections_when_not_provided_to_init(steps=self.steps)
183 self.predict_connections = self.fit_connections
--> 184 self._fit_graph = build_graph(self.fit_connections)
185 self._predict_graph = self._fit_graph
186
~/Projects/korean-ml/venv/lib/python3.9/site-packages/pipegraph/base.py in build_graph(connections)
495 graph.add_nodes_from(connections)
496 for name in connections:
--> 497 current_node = graph.node[name]
498 current_node['name'] = name
499 ascendants_set = set()
AttributeError: 'DiGraph' object has no attribute 'node'
Note: It works as expected if PipeGraph
is replaced with sklearn's Pipeline
Hi there,
I'm using the scikit-API of lightgbm.
from pipegraph.base import PipeGraph, Concatenator
from sklearn.preprocessing import FunctionTransformer
import lightgbm as lgb
import pandas as pd
gbt = lgb.LGBMClassifier(verbose=-1)
rf = lgb.LGBMClassifier(verbose=-1, boosting_type='rf',
subsample=0.7,
colsample_bytree=0.7,
subsample_freq=2)
def meta(X):
X[X<0]=1
return X
meta_sk = FunctionTransformer(meta, validate=False)
concatenator = Concatenator()
steps = [('GBT', gbt),
('concat', concatenator),
('meta', meta_sk),
('RF', rf),
]
connections = { 'GBT': {'X': 'X',
'y': 'y'},
'concat': {'X1': 'GBT',
'X2': 'X'},
'meta': {'X': 'y'},
'RF': {'X': 'concat',
'y': 'meta'},
}
pgraph = PipeGraph(steps=steps, fit_connections=connections)
pgraph.fit(X=df_cv[xvars].to_numpy(),y=df_cv[y_gbt].to_numpy().reshape(-1))
However I got the following error. I assume y is wrongly passed to GBT. Please let me know :)
[LightGBM] [Warning] Unknown parameter: y
ERROR: step.fit call ValueError!
ERROR: _fit.predict call ValueError!
Out[85]:
PipeGraph(fit_connections={'GBT': {'X': 'X', 'y': 'y'},
'RF': {'X': 'concat', 'y': 'meta'},
'concat': {'X1': 'GBT', 'X2': 'X'},
'meta': {'X': 'y'}},
log_level=None,
predict_connections={'GBT': {'X': 'X', 'y': 'y'},
'RF': {'X': 'concat', 'y': 'meta'},
'concat': {'X1': 'GBT', 'X2': 'X'},
'meta': {'X': 'y'}},
steps=[('GBT',
LGBMClassifier(boosting_type='gbdt', class_weight=None,
colsample_b...
LGBMClassifier(boosting_type='rf', class_weight=None,
colsample_bytree=0.7, importance_type='split',
learning_rate=0.1, max_depth=-1,
min_child_samples=20, min_child_weight=0.001,
min_split_gain=0.0, n_estimators=100,
n_jobs=-1, num_leaves=31, objective=None,
random_state=None, reg_alpha=0.0,
reg_lambda=0.0, silent=True, subsample=0.7,
subsample_for_bin=200000, subsample_freq=2,
verbose=-1))])
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.