natekupp / ffx

Fast Function Extraction
http://trent.st/ffx
Other
80 stars 97 forks source link

ElasticNet.fit not working, says "Array contains NaN or infinity" #10

Closed keyvan-m-sadeghi closed 11 years ago

keyvan-m-sadeghi commented 11 years ago

I changed the example in Readme to:

import numpy as np
import ffx

train_X = np.array([(2, 7, 3), (3, 2, 8)]).T
train_y = np.array([5, 9, 11])

test_X = np.array([(1.5, 2.5, 3.5), (2.4, 3.6, 5.2)]).T
test_y = np.array([3.9, 6.1, 8.7])

models = ffx.run(train_X, train_y, test_X, test_y, ["predictor_a", "predictor_b"])
for model in models:
    yhat = model.simulate(test_X)
    print model

I was expecting to simply get "predictor_a + predictor_b"

But instead got:

/usr/local/lib/python2.7/dist-packages/sklearn/linear_model/coordinate_descent.py:418: UserWarning: Objective did not converge. You might want to increase the number of iterations
  ' to increase the number of iterations')
/home/keyvan/Git/ffx/ffx/core.py:805: RuntimeWarning: invalid value encountered in divide
  X_unbiased = (Xin - X_avgs) / X_stds
Traceback (most recent call last):
  File "/home/keyvan/Git/opencog/opencog/python/spatiotemporal/temporal_events/__init__.py", line 2, in <module>
    from generic import TemporalEvent, TemporalInstance, TemporalEventPiecewiseLinear
  File "/home/keyvan/Git/opencog/opencog/python/spatiotemporal/temporal_events/generic.py", line 2, in <module>
    from spatiotemporal.temporal_events.formulas import FormulaCreator, TemporalFormulaConvolution
  File "/home/keyvan/Git/opencog/opencog/python/spatiotemporal/temporal_events/__init__.py", line 14, in <module>
    models = ffx.run(train_X, train_y, test_X, test_y, ["predictor_a", "predictor_b"])
  File "/home/keyvan/Git/ffx/ffx/api.py", line 4, in run
    return core.MultiFFXModelFactory().build(train_X, train_y, test_X, test_y, varnames, verbose)
  File "/home/keyvan/Git/ffx/ffx/core.py", line 443, in build
    next_models = FFXModelFactory().build(train_X, train_y, ss, varnames, verbose)
  File "/home/keyvan/Git/ffx/ffx/core.py", line 653, in build
    ss, varnames, bases, X, y, ss.final_max_num_bases, ss.final_target_train_nmse, verbose)
  File "/home/keyvan/Git/ffx/ffx/core.py", line 683, in _basesToModels
    max_num_bases, target_train_nmse, verbose)
  File "/home/keyvan/Git/ffx/ffx/core.py", line 729, in _pathwiseLearn
    clf.fit(X_unbiased, y_unbiased)
  File "/home/keyvan/Git/ffx/ffx/core.py", line 849, in new_f
    result = f(*args, **kwargs)
  File "/home/keyvan/Git/ffx/ffx/core.py", line 861, in fit
    return ElasticNet.fit(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/sklearn/linear_model/coordinate_descent.py", line 610, in fit
    copy=self.copy_X and self.fit_intercept)
  File "/usr/local/lib/python2.7/dist-packages/sklearn/utils/validation.py", line 124, in atleast2d_or_csc
    "tocsc", force_all_finite)
  File "/usr/local/lib/python2.7/dist-packages/sklearn/utils/validation.py", line 111, in _atleast2d_or_sparse
    force_all_finite=force_all_finite)
  File "/usr/local/lib/python2.7/dist-packages/sklearn/utils/validation.py", line 93, in array2d
    _assert_all_finite(X_2d)
  File "/usr/local/lib/python2.7/dist-packages/sklearn/utils/validation.py", line 27, in _assert_all_finite
    raise ValueError("Array contains NaN or infinity.")
ValueError: Array contains NaN or infinity.

Any idea on how to resolve this?

P.S. I'm not sure that I'm using test_x and test_y correctly, what do they do anyway?

Cheers, K

keyvan-m-sadeghi commented 11 years ago

Just noticed that this issue might be a duplicate of #4

jmmcd commented 11 years ago

Closing as duplicate of #4.

You're not doing anything wrong with test_X and test_y. They're for out-of-sample testing. They just need to have the right shapes, which they do in your example.