Giter VIP home page Giter VIP logo

pykliep's People

Contributors

srome avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pykliep's Issues

AttributeError: DensityRatioEstimator instance has no attribute '_sigma'

Traceback (most recent call last):
File "challenge.py", line 187, in
weights = kliep.predict(X)
File "challenge.py", line 180, in predict
return np.dot(self._phi(X, sigma=sigma), self._alpha).reshape((X.shape[0],))
File "challenge.py", line 150, in _phi
sigma = self._sigma
AttributeError: DensityRatioEstimator instance has no attribute '_sigma'

code does not work. my train and test data 1000x132 , 200x132.

This function returns a zero matrix

def _phi(self, X, sigma=None):

    if sigma is None:
        sigma = self._sigma
    print(sigma , "****** sigma");
    print(X.shape)
    print((X-self._test_vectors).shape)
    #exit(-1)

    if self._phi_fitted:
        #print(np.exp(-np.sum((X-self._test_vectors)**2, axis=-1)/(2*sigma**2)))
        return np.exp(-np.sum((X-self._test_vectors)**2, axis=-1)/(2*sigma**2))
    raise Exception('Phi not fitted.')

'

Memory Error

Thanks for your implementation. I run the code in a training set of ~ 150k rows and a test set of ~ 80k rows with ~24 features and get Memory Error. The stack trace is:

  File "modeling.py", line 552, in score
    kliep.fit(X_train, X_test) # keyword arguments are X_train and X_test
  File "pykliep.py", line 83, in fit
    sigma=sigma)
  File "pykliep.py", line 124, in _fit
    sigma=sigma)
  File "pykliep.py", line 162, in _find_alpha
    b = self._phi(X_train, sigma).sum(axis=0) / X_train.shape[0]
  File "pykliep.py", line 154, in _phi
    return np.exp(-np.sum((X-self._test_vectors)**2, axis=-1)/(2*sigma**2))
MemoryError```

What is the possible cause of this error?

dict object has no attribute iteritems

I am trying to follow the example and fit the model but keep getting the below error

My code looks like below

kliep = DensityRatioEstimator()
kliep.fit(X_train.values, X_test.values) # keyword arguments are X_train and X_test
weights = kliep.predict(X_train.values)

So, I went to the code file and replaced iteritems with items for python 3 but that still doesn't solve the error

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [83], in <cell line: 2>()
      1 kliep = DensityRatioEstimator()
----> 2 kliep.fit(X_train.values, X_test.values) # keyword arguments are X_train and X_test
      3 weights = kliep.predict(X_train.values)

File ~\Downloads\pykliep.py:85, in DensityRatioEstimator.fit(self, X_train, X_test, alpha_0)
     79             j_scores[(num_param,sigma)][k-1] = self._fit(X_train=X_train, 
     80                                              X_test=X_test_fold,
     81                                              num_parameters = num_param,
     82                                              sigma=sigma)
     83         j_scores[(num_param,sigma)] = np.mean(j_scores[(num_param,sigma)])
---> 85 sorted_scores = sorted([x for x in j_scores.iteritems() if np.isfinite(x[1])], key=lambda x :x[1], reverse=True)
     86 if len(sorted_scores) == 0:
     87     warnings.warn('LCV failed to converge for all values of sigma.')

AttributeError: 'dict' object has no attribute 'iteritems'

KeyError: 44

I am getting keyerror while running the code. What could be the issue ?

`KeyError Traceback (most recent call last)
/Application/DataScience/Anaconda/anaconda3/lib/python3.6/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
3077 try:
-> 3078 return self._engine.get_loc(key)
3079 except KeyError:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 44

During handling of the above exception, another exception occurred:

KeyError Traceback (most recent call last)
in ()
2
3 kliep = DensityRatioEstimator()
----> 4 kliep.fit(X_train, X_test) # keyword arguments are X_train and X_test
5 # weights = kliep.predict(X_train)
6

~/nma/Shankar/pykliep.py in fit(self, X_train, X_test, alpha_0)
59 np.random.seed(self.random_state)
60 X_test_shuffled = X_test.copy()
---> 61 np.random.shuffle(X_test_shuffled)
62
63 j_scores = {}

mtrand.pyx in mtrand.RandomState.shuffle()

mtrand.pyx in mtrand.RandomState.shuffle()

/Application/DataScience/Anaconda/anaconda3/lib/python3.6/site-packages/pandas/core/frame.py in getitem(self, key)
2686 return self._getitem_multilevel(key)
2687 else:
-> 2688 return self._getitem_column(key)
2689
2690 def _getitem_column(self, key):

/Application/DataScience/Anaconda/anaconda3/lib/python3.6/site-packages/pandas/core/frame.py in _getitem_column(self, key)
2693 # get column
2694 if self.columns.is_unique:
-> 2695 return self._get_item_cache(key)
2696
2697 # duplicate columns & possible reduce dimensionality

/Application/DataScience/Anaconda/anaconda3/lib/python3.6/site-packages/pandas/core/generic.py in _get_item_cache(self, item)
2487 res = cache.get(item)
2488 if res is None:
-> 2489 values = self._data.get(item)
2490 res = self._box_item_values(item, values)
2491 cache[item] = res

/Application/DataScience/Anaconda/anaconda3/lib/python3.6/site-packages/pandas/core/internals.py in get(self, item, fastpath)
4113
4114 if not isna(item):
-> 4115 loc = self.items.get_loc(item)
4116 else:
4117 indexer = np.arange(len(self.items))[isna(self.items)]

/Application/DataScience/Anaconda/anaconda3/lib/python3.6/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
3078 return self._engine.get_loc(key)
3079 except KeyError:
-> 3080 return self._engine.get_loc(self._maybe_cast_indexer(key))
3081
3082 indexer = self.get_indexer([key], method=method, tolerance=tolerance)

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 44`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.