10BC0 AttributeError: 'SymbolicRegressor' object has no attribute '_validate_data' · Issue #307 · trevorstephens/gplearn · GitHub
[go: up one dir, main page]

Skip to content

AttributeError: 'SymbolicRegressor' object has no attribute '_validate_data' #307

@k3ybladewielder

Description

@k3ybladewielder

Describe the bug

Error when try to it a model.

Expected behavior

The expected behavior is for the model to fit on the data.

Actual behavior

The actual behavior is the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[14], line 17
      1 # 5) Regressão simbólica
      2 model = SymbolicRegressor(
      3     population_size=500,
      4     generations=20,
   (...)
     14     verbose=0
     15 )
---> 17 model.fit(X_scaled, y)

File ~/symbolic_classifier/.venv/lib/python3.10/site-packages/gplearn/genetic.py:312, in BaseSymbolic.fit(self, X, y, sample_weight)
    309     self.n_classes_ = len(self.classes_)
    311 else:
--> 312     X, y = self._validate_data(X, y, y_numeric=True)
    314 hall_of_fame = self.hall_of_fame
    315 if hall_of_fame is None:

AttributeError: 'SymbolicRegressor' object has no attribute '_validate_data'

Steps to reproduce the behavior

Code gist:

# 1) Dataset de exemplo (10 textos: 5 A, 5 B)
texts = [
    "Produto ótimo e recomendo",
    "Excelente serviço e bom atendimento",
    "Gostei muito da compra",
    "Entrega rápida e produto de qualidade",
    "Funcionou perfeitamente, estou satisfeito",
    "Produto ruim e não funciona",
    "Péssimo atendimento, não gostei",
    "Demorado e de baixa qualidade",
    "Horrível, veio quebrado",
    "Decepcionante e caro"
]
y = np.array([0,0,0,0,0,1,1,1,1,1])  # 0=A, 1=B

# 2) TF-IDF
vectorizer = TfidfVectorizer(lowercase=True)
X_tfidf = vectorizer.fit_transform(texts).toarray()

# 3) PCA para reduzir para 10 features
NUM_COMPONENTES = 10
pca = PCA(n_components=NUM_COMPONENTES, random_state=42)
X_reduced = pca.fit_transform(X_tfidf)

# 4) Normalização
scaler = MinMaxScaler()
X_scaled = scaler.fit_transform(X_reduced)

# 5) Regressão simbólica
model = SymbolicRegressor(
    population_size=500,
    generations=20,
    stopping_criteria=0.01,
    function_set=('add', 'sub', 'mul', 'div', 'log', 'sqrt'),
    p_crossover=0.7,
    p_subtree_mutation=0.1,
    p_hoist_mutation=0.05,
    p_point_mutation=0.1,
    max_samples=1.0,
    parsimony_coefficient=0.001,
    random_state=42,
    verbose=0
)

model.fit(X_scaled, y)

System information

Linux-6.8.0-87-generic-x86_64-with-glibc2.35
Python 3.10.12 (main, Aug 15 2025, 14:32:43) [GCC 11.4.0]
NumPy 2.2.6
SciPy 1.15.3
Scikit-Learn 1.7.2
Joblib 1.5.2
gplearn 0.4.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0