natekupp / ffx

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

FFX crashes when X has only 1 variable #3

Closed jmmcd closed 11 years ago

jmmcd commented 11 years ago

This code produces an "iteration over 0-d array" error, pasted below. I think the reason is that FFX calls list() on the coefficients, which have been numpy.squeeze()ed by sklearn ElasticNet. I don't see why they squeeze it, but ok. I guess the solution is to hack it by checking if the array is 0-d, and if so just reshape it. I'll commit that fix and then close this issue. Just raising it for posterity.

#!/usr/bin/env python

import numpy as np
import ffx

# This creates a dataset of 1 predictor
train_X = np.array([[0, 1, 2, 3]]).T
train_y = np.array([0, 1, 4, 9])

test_X = np.array([[4, 5, 6, 7]]).T
test_y = np.array([16, 25, 36, 49])

models = ffx.run(train_X, train_y, test_X, test_y, ["x"])
Traceback (most recent call last):
  File "./test2.py", line 12, in <module>
    models = ffx.run(train_X, train_y, test_X, test_y, ["x"])
  File "/Users/jmmcd/Documents/vc/ffx/ffx/api.py", line 4, in run
    return core.MultiFFXModelFactory().build(train_X, train_y, test_X, test_y, varnames, verbose)
  File "/Users/jmmcd/Documents/vc/ffx/ffx/core.py", line 443, in build
    next_models = FFXModelFactory().build(train_X, train_y, ss, varnames, verbose)
  File "/Users/jmmcd/Documents/vc/ffx/ffx/core.py", line 584, in build
    ss, varnames, order1_bases, X, y, max_num_bases, target_train_nmse, verbose)
  File "/Users/jmmcd/Documents/vc/ffx/ffx/core.py", line 683, in _basesToModels
    max_num_bases, target_train_nmse, verbose)
  File "/Users/jmmcd/Documents/vc/ffx/ffx/core.py", line 740, in _pathwiseLearn
    coefs = self._rebiasCoefs([0.0] + list(cur_unbiased_coefs), X_stds, X_avgs, y_std, y_avg)
TypeError: iteration over a 0-d array
jmmcd commented 11 years ago

Fixed with 4846eba.