Mg30 / genpipes

Library to write readable and reproducible data processing code using python.
GNU General Public License v3.0
23 stars 3 forks source link

module 'genpipes' has no attribute 'map' #15

Closed Anonymous752 closed 1 year ago

Anonymous752 commented 1 year ago

I have tried this code and I am facing error with map: "gp.map(fit_random_forest, batch_size=10) AttributeError: module 'genpipes' has no attribute 'map' "

import genpipes as gp from sklearn.ensemble import RandomForestClassifier from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split

Load the Iris dataset

iris = load_iris()

Split the data into training and testing sets

X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.3)

Define a function to fit a random forest classifier

def fit_random_forest(X, y): rf = RandomForestClassifier() rf.fit(X, y) return rf

Define the pipeline using GenPipes

pipeline =( gp.map(fit_random_forest, batch_size=10) | gp.reduce(lambda x, y: x + y) )

Run the pipeline on the training data

models = pipeline(X_train, y_train)

Evaluate the models on the testing data

acc = [model.score(X_test, y_test) for model in models]

print(f"Accuracy: {acc}")

Mg30 commented 1 year ago

Hello, As the error message suggests, genpipes has no attribute map. In most cases, reading the readme is a good starting point.