本文整理汇总了Python中sklearn.preprocessing.PolynomialFeatures类 的典型用法代码示例。如果您正苦于以下问题:Python PolynomialFeatures类的具体用法?Python PolynomialFeatures怎么用?Python PolynomialFeatures使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PolynomialFeatures类 的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self):
self.theta = T.matrix()
# define output for b
combinations = PolynomialFeatures._combinations(2, 3, False, False)
n_output_features_ = sum(1 for _ in combinations) + 1
self.A_b = theano.shared(
value=np.ones((n_output_features_,), dtype=theano.config.floatX),
borrow=True, name='A_b')
self.b_b = theano.shared(value=1.,
borrow=True, name='b_b')
combinations = PolynomialFeatures._combinations(2, 3, False, False)
L = [(self.theta[:, 0] ** 0).reshape([-1, 1])]
for i, c in enumerate(combinations):
L.append(self.theta[:, c].prod(1).reshape([-1, 1]))
self.XF3 = T.concatenate(L, axis=1)
b = (T.dot(self.XF3, self.A_b) + self.b_b).reshape([-1, 1])
# define output for k
combinations = PolynomialFeatures._combinations(2, 2, False, False)
n_output_features_ = sum(1 for _ in combinations) + 1
self.rho_k = theano.shared(
value=np.ones((n_output_features_,), dtype=theano.config.floatX),
borrow=True, name='rho_k')
combinations = PolynomialFeatures._combinations(2, 2, False, False)
L = [(self.theta[:, 0] ** 0).reshape([-1, 1])]
for i, c in enumerate(combinations):
L.append(self.theta[:, c].prod(1).reshape([-1, 1]))
self.XF2 = T.concatenate(L, axis=1)
k = T.dot(self.XF2, self.rho_k).reshape([-1, 1])
self.outputs = [T.concatenate([b, k], axis=1)]
self.inputs = [self.theta]
self.trainable_weights = [self.A_b, self.b_b, self.rho_k]
开发者ID:teopir, 项目名称:ifqi, 代码行数:35, 代码来源:pbo_grad_test.py
示例2: prob_max
def prob_max(x):
poly=PolynomialFeatures(degree=2)
x=poly.fit_transform(x)
####define best fit coefficient arrays
theta_0=np.array([5.017034759466216798e+00,-4.953976374628412532e-02,-5.853604893727188709e-03,-1.732076056200582692e-01,4.646876717720006822e-02,-2.787195959859810248e-04,-1.222728739255723981e-07,6.120106921025333935e-02,4.604924515407455714e-06,-1.475861223279032741e-01,-4.060326310707941784e-09,1.177855732870812001e-02,3.113699082333943463e-02,-8.110887996756119586e-12,-1.113811480228766704e-05,-1.501651909640449069e-07,-2.190797370951344465e-06,-1.718990505473245339e-05,-1.199898098055512375e-13,-2.571924773608319866e-07,-2.147269697093823931e-12,-3.256296536440236682e-05,-2.581007347409745425e-05,1.392377894191479523e-03,-4.129157456238496948e-02,-1.811677361205055875e-02,-7.083807139833804416e-06,4.116671309652412958e-02,3.361594896247442773e-04,-8.223201336497298203e-03,-1.862209709284966395e-07,1.527880447451521184e-02,-3.672245027121902317e-02,-4.975817315933817863e-10,-6.237344094335352815e-04,-1.217106713769066128e-05,-1.489610233924158246e-04,-1.156461881655085214e-03,-5.159561821638818347e-12,-1.884192981459143558e-05,-1.825179242529750414e-10,-5.438522396156177874e-07,4.167833399722946711e-05,5.607144654864255374e-03,-3.093787958451529527e-02,-2.041422430639949412e-04,7.895983583095988675e-03,1.293062803926413491e-02,5.899640081165494730e-03,-1.021176015149306061e-05,8.486220614842233598e-03,5.822368958314040610e-03,-2.243937133831174112e-08,-8.464968966797879399e-03,-1.906386791427585779e-04,-1.795243901952780228e-03,-1.046895210502369993e-02,-3.330917120202175767e-10,-4.235251180738666644e-04,-5.694559236692822056e-09,-1.583929993116185621e-03,1.629024063907276165e-01,-6.967989967191325247e-03,-3.673107962032413740e-06,-2.280088579624509337e-01,1.726846693277796316e-04,1.013912471248917396e-01,-7.647706080406362405e-08,-3.240179256710575273e-01,1.214811767523774205e-01,-3.401281050759457049e-10,-1.670938331047893612e-07,-7.369899627351106136e-06,-9.856333774434332797e-05,-4.534506039623955074e-05,-9.599184784444142215e-12,-5.151527253102048208e-06,-1.030689454605035745e-10,4.646876717720006822e-02,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-2.787195959859810248e-04,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-1.222728739255723981e-07,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,6.120106921025333935e-02,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,4.604924515407455714e-06,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-1.475861223279032741e-01,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-4.060326310707941784e-09,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,1.177855732870812001e-02,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,3.113699082333943463e-02,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-8.110887996756119586e-12,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-1.113811480228766704e-05,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-1.501651909640449069e-07,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-2.190797370951344465e-06,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-1.718990505473245339e-05,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-1.199898098055512375e-13,0.000000000000000000e+00,0.000000000000000000e+00,-2.571924773608319866e-07,0.000000000000000000e+00,-2.147269697093823931e-12])
theta_1=np.array([-9.861773710361221745e+00,1.930173314618176539e-01,6.178220889126870112e-03,9.590504030349773779e-02,-2.071552578564340164e-01,1.061401114719375260e-01,3.276754675639340086e-02,-1.761411784826558136e-02,-1.219468120911304441e-06,-9.174348236081142360e-02,2.132582599900693932e-02,-1.168137887722866912e-02,1.014151234082172059e-01,9.598987135568204463e-04,-4.542651588690940767e-02,-7.514592183950008714e-04,1.113651743862166532e-03,3.535033504077587929e-02,1.348878960300472899e-06,4.158088521609443200e-02,1.744377835470558925e-06,-8.830070079582454969e-04,-6.118986593694282407e-05,-4.784785490618059583e-04,6.231388236713353984e-02,1.984193321394733464e-02,3.807758267577563555e-02,-1.857758661936751918e-02,-8.902117282652563328e-05,1.684544497032977118e-03,-4.354918224284388961e-02,8.135671785350261087e-03,1.838040795364327554e-03,4.648089395429296639e-02,1.603282923510754299e-02,-5.706248765095311287e-02,6.474737189221846378e-02,-1.666585875194382532e-02,5.800179529291954185e-05,6.960244357250958136e-02,1.482721160150063508e-04,-5.299760763074679222e-07,-4.512899253144341872e-05,-9.330422825892547602e-04,-3.692049341246863322e-04,-7.641113350637301687e-04,-3.553288559473667197e-04,-3.424266483519060756e-03,4.323086081437536800e-04,-4.955185382381825611e-04,-5.468633412309427573e-03,3.023053081335558886e-04,2.032432933463332054e-03,-1.868881428527514009e-04,5.907286677952040300e-03,1.224575926635180362e-03,1.491552037995557810e-03,3.744487993794240379e-03,-1.585824627682363985e-03,4.626090019667926378e-03,2.914276434916693195e-04,-6.421237001048539506e-04,1.343912634023189216e-02,1.202887078507273999e-02,4.579648647433440592e-03,-4.573005453417482836e-05,-2.603037492365091118e-02,1.093608117200833424e-01,3.532167048002045617e-01,-1.790610728587208392e-02,-7.755213616683120925e-02,-5.213887650785711293e-03,-1.747560651202587356e-01,-4.635745132339050972e-02,-5.689835106400319142e-02,1.079103168240419384e-04,8.490464847112829186e-03,8.373013610258914587e-05,-2.071552578564340164e-01,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,1.061401114719375260e-01,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,3.276754675639340086e-02,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-1.761411784826558136e-02,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-1.219468120911304441e-06,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-9.174348236081142360e-02,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,2.132582599900693932e-02,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-1.168137887722866912e-02,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,1.014151234082172059e-01,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,9.598987135568204463e-04,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-4.542651588690940767e-02,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-7.514592183950008714e-04,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,1.113651743862166532e-03,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,3.535033504077587929e-02,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,1.348878960300472899e-06,0.000000000000000000e+00,0.000000000000000000e+00,4.158088521609443200e-02,0.000000000000000000e+00,1.744377835470558925e-06])
theta_2=np.array([-2.604982997969506187e+01,2.522175474048852784e-01,6.275718741926675920e-03,1.273176496282046599e-01,-1.716361908427019300e-01,-8.312891928874267811e-02,4.068642760504040390e-02,-2.445951924349220458e-02,-8.746331909292573688e-07,-1.542657353435612777e-02,-1.765684782956331370e-02,-3.195224775777173168e-04,2.484350665759416446e-02,4.813993958703906978e-03,1.759866699719525307e-01,5.747258345660388864e-04,-1.022129045161229450e-03,5.567310929387970370e-02,-9.063835339582872293e-07,-8.930479773136143495e-02,-9.138473645722535673e-07,-7.459379939882724523e-04,-4.125238423403655301e-05,-4.278814974555324602e-04,1.234252674940865789e-02,4.708747007997553247e-02,2.657070242802176546e-02,6.926664427951148562e-02,-6.384822293781164664e-05,4.964280033292678418e-02,9.853135356553717472e-02,-2.621681271491586862e-02,6.630289966406467672e-02,-2.208061355155441774e-01,4.922574438806641417e-02,4.310173077725486246e-02,-5.622794820973487512e-02,1.006576646572381883e-01,-3.897449196020566275e-05,-7.080593340274707326e-03,-7.767702598866720021e-05,-3.990070230109308789e-07,-1.651061082255117919e-05,1.537024690049966936e-03,8.005698436542285070e-04,8.994568249232704014e-04,5.470196351385650481e-04,-2.455970000128474082e-03,4.988277998095904915e-04,1.262763556509414152e-03,4.601679612131920685e-03,-1.194497842888761268e-04,2.882224654372331132e-03,5.875401491502118233e-04,-2.458015081252763658e-03,5.859965255224170106e-04,-2.547687917446368093e-04,-2.516120690268733393e-03,2.300462784971263851e-03,-2.423523210845587861e-03,-1.539288004294190964e-04,-1.260645266526524456e-02,-2.136594669075533859e-02,-1.240381092246360673e-02,1.775253607050698845e-02,-3.279874465984122252e-05,1.667948986384345557e-03,-1.177656364439296638e-01,-8.947706286380961412e-04,5.282554584883104691e-03,9.528953029071411673e-02,-1.953324553475337816e-03,1.692159896831275101e-01,6.332910268512657870e-02,-3.059270306265245501e-02,-7.251068271668771679e-05,-2.748819360572268139e-02,-4.386467349947201168e-05,-1.716361908427019300e-01,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-8.312891928874267811e-02,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,4.068642760504040390e-02,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-2.445951924349220458e-02,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-8.746331909292573688e-07,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-1.542657353435612777e-02,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-1.765684782956331370e-02,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-3.195224775777173168e-04,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,2.484350665759416446e-02,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,4.813993958703906978e-03,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,1.759866699719525307e-01,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,5.747258345660388864e-04,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-1.022129045161229450e-03,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,5.567310929387970370e-02,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-9.063835339582872293e-07,0.000000000000000000e+00,0.000000000000000000e+00,-8.930479773136143495e-02,0.000000000000000000e+00,-9.138473645722535673e-07])
theta_3=np.array([-2.972725322795918140e-02,-2.504227156229747453e-01,-9.722118342779062158e-03,1.229149113213241912e-01,2.039923850853684467e-02,-1.805107341267933943e-02,7.334563069172345476e-03,-6.475321568310828764e-04,-8.474944289249388250e-08,9.714545617984883855e-05,-2.075035998257516458e-07,-1.221820060933139164e-05,-1.714475447964966190e-02,-2.129377838506303893e-03,-1.277321374533818017e-06,-2.380156363764723250e-06,-5.273025783548628525e-06,-1.984111789391731009e-03,-1.335426121119178434e-07,3.339996589013074558e-04,-2.141039464532945376e-07,2.576647414932395786e-03,2.945797215512836505e-06,-1.895000552612198606e-04,-1.462288947682845522e-02,-1.951654268095479733e-02,-1.630737487857820273e-02,-5.655678104343885015e-02,-6.186709331152055607e-06,-2.000570956968860184e-02,-1.460798045208372536e-05,-9.892777618470509349e-04,-6.134943418829629652e-02,5.204243735868804843e-02,-6.976997540713989398e-05,-1.924795146172466416e-04,-3.585644621246710678e-04,-8.751744876445026466e-02,-5.742332320812468485e-06,-2.493414480788682872e-02,-1.819883544853002577e-05,1.673188626427698019e-06,-2.199004526442708865e-05,3.929065891591175703e-03,3.411106034336343351e-03,4.689455918427083009e-03,-1.623583183295337906e-02,-2.379764356421232188e-04,4.563617516957610247e-03,-5.845377676580722996e-04,-5.550332977089329420e-03,5.817926665026248653e-03,3.489254807540806587e-03,-8.968364091790517831e-04,-2.770023159211470760e-03,-4.227833625220314175e-03,1.685174688793472349e-03,-3.707142912226834078e-04,-5.865829701672146956e-03,-5.678036659941369801e-04,8.344188249964974876e-05,-2.863247383273172242e-02,-6.482258485425367728e-03,-4.199374526758931081e-02,-1.256077522453134809e-02,-3.178104108468527999e-06,-3.440396173308768457e-02,-9.901849306080791411e-06,-3.180423753092536477e-05,-7.452030759889874401e-02,-6.907406950607837548e-02,5.971308793973397274e-07,-1.155260382492086013e-04,-2.332571299853613211e-04,1.410515664042338024e-01,-1.068340896895342663e-05,2.499449671921087357e-01,-1.027698942975813230e-05,2.039923850853684467e-02,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-1.805107341267933943e-02,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,7.334563069172345476e-03,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-6.475321568310828764e-04,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-8.474944289249388250e-08,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,9.714545617984883855e-05,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-2.075035998257516458e-07,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-1.221820060933139164e-05,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-1.714475447964966190e-02,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-2.129377838506303893e-03,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-1.277321374533818017e-06,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-2.380156363764723250e-06,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-5.273025783548628525e-06,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-1.984111789391731009e-03,0.000000000000000000e+00,0.000000000000000000e+00,0.000000000000000000e+00,-1.335426121119178434e-07,0.000000000000000000e+00,0.000000000000000000e+00,3.339996589013074558e-04,0.000000000000000000e+00,-2.141039464532945376e-07,])
#####calculate probabilities
z_0=np.sum(x*theta_0)
z_1=np.sum(x*theta_1)
z_2=np.sum(x*theta_2)
z_3=np.sum(x*theta_3)
p_0=1./(1.+np.exp(-z_0))
p_1=1./(1.+np.exp(-z_1))
p_2=1./(1.+np.exp(-z_2))
p_3=1./(1.+np.exp(-z_3))
prob_arra=np.array([p_0, p_1, p_2, p_3])
return prob_arra.argmax()
开发者ID:dsrub, 项目名称:web_app, 代码行数:28, 代码来源:predict_prob.py
示例3: linearRegreSin
def linearRegreSin(url,degree):
[a,b] = getData(url)
trainA = a[0:139]
trainB = b[0:139]
testA = a[140:]
testB = b[140:]
poly = PolynomialFeatures(degree)
trainA = np.float64(poly.fit_transform(trainA))
testA = np.float64(poly.fit_transform(testA))
theta = np.dot(np.dot(np.linalg.inv(np.dot(trainA.T,trainA)),trainA.T),trainB)
plt.figure(1)
plt.xlabel('x')
plt.ylabel('y')
plt.title('data')
plt.plot(trainA[:,1],trainB,"r*")
y=np.dot(trainA, theta)
print(pow(sum((y-trainB)**2),1/2)/140) #print MSE
y=np.dot(testA, theta)
#plt.plot(testA[:,1], testB, "r.")
plt.plot(testA[:,1],y,"k*")
print(pow(sum((y-testB)**2),1/2)/60) #print MSE
plt.show()
print(theta)
开发者ID:MorPhingG, 项目名称:MachineLearning, 代码行数:25, 代码来源:LinearRegression.py
示例4: myTradingSystem
def myTradingSystem(DATE, OPEN, HIGH, LOW, CLOSE, VOL, OI, P, R, RINFO, exposure, equity, settings):
""" This system uses linear regression to allocate capital into the desired equities"""
# Get parameters from setting
nMarkets = len(settings['markets'])
lookback = settings['lookback']
dimension = settings['dimension']
threshold = settings['threshold']
pos = np.zeros(nMarkets, dtype=np.float)
poly = PolynomialFeatures(degree=dimension)
for market in range(nMarkets):
reg = linear_model.LinearRegression()
try:
reg.fit(poly.fit_transform(np.arange(lookback).reshape(-1, 1)), CLOSE[:, market])
trend = (reg.predict(poly.fit_transform(np.array([[lookback]]))) - CLOSE[-1, market]) / CLOSE[-1, market]
if abs(trend[0]) < threshold:
trend[0] = 0
pos[market] = np.sign(trend)
# for NaN data set position to 0
except ValueError:
pos[market] = .0
return pos, settings
开发者ID:marcoracer, 项目名称:quantiacs-python, 代码行数:28, 代码来源:LinearRegression.py
示例5: poly_model
def poly_model(ins,outs,degrees):
poly = PolynomialFeatures(degree=degrees)
X = poly.fit_transform(ins)
regr = linear_model.LinearRegression()
regr.fit(X, outs)
print_model("poly-"+str(degrees), regr, X, outs)
开发者ID:verdverm, 项目名称:pypge, 代码行数:7, 代码来源:theline.py
示例6: interactor
def interactor(df):
""" This function takes in a data frame and creates binary interaction
terms from all numerical and categorical variables as well as the assessment
questions, and outputs a data frame """
my_data_complete = df.dropna()
# interactions can only be done for non-missings
colnames = list(my_data_complete.columns.values)
# id and date columns
id_cols_list = [
x
for x in colnames # only for continuous vars
if not (bool(re.search("_N$", x)) | bool(re.search("_C$", x)) | bool(re.search("_Q$", x)))
]
# actual feature columns - to make interactions from
new_cols_list = [
x
for x in colnames # only for continuous vars
if (bool(re.search("_N$", x)) | bool(re.search("_C$", x)) | bool(re.search("_Q$", x)))
]
othervars = my_data_complete[id_cols_list]
little_df = my_data_complete[new_cols_list]
# computing all binary interaction terms
poly = PolynomialFeatures(degree=2, interaction_only=True)
theints = pd.DataFrame(poly.fit_transform(little_df))
theints = theints.drop(theints.columns[0], axis=1) # dropping the first column
theints.columns = list(new_cols_list + list(itertools.combinations(new_cols_list, 2)))
# concatenating the interaction terms to the original data frame
df = pd.DataFrame(othervars.join(theints))
new_features = theints.columns.values
return df, new_features
开发者ID:pombredanne, 项目名称:babies-public, 代码行数:31, 代码来源:features.py
示例7: batterLife_chargeMoreThan4
def batterLife_chargeMoreThan4(chargeTime):
import numpy as np
trainDataArr = np.genfromtxt("trainingdata_batteryLife.txt", delimiter = ",")
trainDataArr = trainDataArr[trainDataArr[ :,0] > 4]
trainData = trainDataArr[:, 0]
trainData = trainData.reshape(-1,1)
trainValue = trainDataArr[:,1]
testData = np.array(chargeTime)
testData = testData.reshape(-1,1)
from sklearn.preprocessing import PolynomialFeatures
from sklearn import linear_model
# Plot outputs
import matplotlib.pyplot as plt
plt.scatter(trainData, trainValue, color='black')
plt.xticks(())
plt.yticks(())
plt.show()
# Fit regression model
poly = PolynomialFeatures(degree = 1)
trainData_ = poly.fit_transform(trainData)
testData_ = poly.fit_transform(testData)
clf = linear_model.LinearRegression()
clf.fit(trainData_, trainValue)
return clf.predict(testData_)
开发者ID:JaneEvans, 项目名称:Useful-Python3-Codes, 代码行数:28, 代码来源:2-level-linear-Regression_batteryLife.py
示例8: hidden_layer
def hidden_layer(self, X, w):
# The dimension of matrix Z is (R + 1) * m. The extra dimension is constant
# extra 1 dimension for bias.
Z = sigmoid(np.dot(X, w.T))
p = PolynomialFeatures(degree = 1)
Z = p.fit_transform(Z)
return Z
开发者ID:AngeloK, 项目名称:cs584-hws, 代码行数:7, 代码来源:mlp.py
示例9: learning_curve
def learning_curve(classifier, X, y, cv, sample_sizes,
degree=1, pickle_path=None, verbose=True):
""" Learning curve
"""
learning_curves = []
for i, (train_index, test_index) in enumerate(cv):
X_train = X[train_index]
X_test = X[test_index]
y_train = y[train_index]
y_test = y[test_index]
if degree > 1:
poly = PolynomialFeatures(degree=degree, interaction_only=False, include_bias=True)
X_train = poly.fit_transform(X_train)
X_test = poly.transform(X_test)
lc = []
for sample in sample_sizes:
classifier.fit(X_train[:sample], y_train[:sample])
# apply classifier on test set
y_pred = classifier.predict(X_test)
confusion = metrics.confusion_matrix(y_test, y_pred)
lc.append(balanced_accuracy_expected(confusion))
learning_curves.append(lc)
if verbose: print(i, end=' ')
# pickle learning curve
if pickle_path:
with open(pickle_path, 'wb') as f:
pickle.dump(learning_curves, f, protocol=4)
if verbose: print()
开发者ID:davidjwu, 项目名称:mclass-sky, 代码行数:34, 代码来源:classifier.py
示例10: get_cl
def get_cl(tau, consider='EE', degree=5):
if consider == 'EE':
values = values_EE
else:
values = values_BB
v = values#[:100]
p = points#[:100]
poly = PolynomialFeatures(degree=degree)
# Vandermonde matrix of pre-computed paramter values.
X_ = poly.fit_transform(p.reshape(-1,1))
predict = np.array([tau]).reshape(1,-1)
# Creates matrix of values you want to estimate from the existing
# measurements. Computation speed scales very slowly when you ask for
# estimate of many sets of parameters.
predict_ = poly.fit_transform(predict)
clf = LinearRegression()
estimate = []
for l in range(2, v.shape[1]):
values_l = v[:,l]
clf.fit(X_, values_l)
estimate_l = clf.predict(predict_)
estimate.append(estimate_l)
estimate = np.array(estimate)
ell = np.arange(2, l+1)
Z = 2*np.pi/(ell*(ell+1))
return ell, Z*estimate[:,0]
开发者ID:pqrs6, 项目名称:clee-fast, 代码行数:31, 代码来源:main_tau.py
示例11: polynomial_expansion
def polynomial_expansion(self, rank=2):
"""
Expand the features with polynonial of rank rnank
"""
pf = PolynomialFeatures(degree=2)
self.X_red = pf.fit_transform(self.X_red)
self.X_white = pf.fit_transform(self.X_white)
开发者ID:Borisdatzar, 项目名称:machine_learning_techniques, 代码行数:7, 代码来源:wine_preprocesser.py
示例12: test_polynomial_fits
def test_polynomial_fits(x, y, n_comps, model, k_folds=3):
for i in range(1,6):
poly = PolynomialFeatures(degree=i)
poly_x = poly.fit_transform(x)
r2_mean, r2_std, mse_mean, mse_std = run_conventional_linkage(poly_x, y, n_comps, model)
print r2_mean, r2_std, mse_mean, mse_std
print
开发者ID:Materials-Informatics-Class-Fall2015, 项目名称:MIC-Ternary-Eutectic-Alloy, 代码行数:7, 代码来源:smart_pipeline.py
示例13: analysis_7
def analysis_7(df_Coredata):
""" 多次元多項式モデル """
#https://www.jeremyjordan.me/polynomial-regression/
X = df_Coredata[['d','e','f','g','i']]
y = df_Coredata['j']
# グラフのスタイルを指定
sns.set(style = 'whitegrid', context = 'notebook')
# 変数のペアの関係をプロット
#sns.pairplot(df_Coredata)
#plt.show()
#X_train, X_test, y_train, y_test = train_test_split(X,y,random_state = 0)
#lr = linear_model.LinearRegression().fit(X_train, y_train)
#print("Trainng set score: {:.2f}".format(lr.score(X_train, y_train)))
#print("Test set score: {:.2f}".format(lr.score(X_test, y_test)))
### データのスケール変換
# 標準化
std_Scaler = StandardScaler()
data_std = std_Scaler.fit_transform(X)
mmx_Scaler =MinMaxScaler()
X_scaled = mmx_Scaler.fit_transform(X)
#X_test_scaled = scaler.transform(X_test)
#print(X_train_scaled)
poly = PolynomialFeatures(degree = 2).fit(data_std)
print(poly.get_feature_names())
开发者ID:Yotaro723, 项目名称:test_2, 代码行数:33, 代码来源:DoE.py
示例14: main
def main():
testfile = sys.argv[1]
modelfile = sys.argv[2]
polyorder = int(sys.argv[3])
testweeks = sys.argv[4]
test_data = np.genfromtxt(testfile, delimiter=',', skip_header=1)
X = test_data[:,:-1]
y = test_data[:,-1]
poly = PolynomialFeatures(degree=polyorder)
Xpoly = poly.fit_transform(X)
with open(modelfile, 'rb') as model, open(testweeks) as weeks:
lr = pickle.load(model)
games_per_week = (int(line) for line in weeks)
ranges = []
pos = 0
for week in games_per_week:
newpos = pos + week
ranges.append( (pos, newpos) )
pos = newpos
print('W\tL\tPoints')
weekly_results = (evaluate_week(week, Xpoly, y, lr) for week in ranges)
for result in weekly_results:
print('\t'.join(str(piece) for piece in result))
开发者ID:atmapersaud, 项目名称:nfl-predictions, 代码行数:27, 代码来源:nfl-evaluate.py
示例15: mvr
def mvr(data):
x = data[:, 0:len(data[0])-1]
y = data[:, -1]
minTestingError = np.inf
for dim in xrange(1,3):
if(dim > 1):
print("Mapping into higher dimension of {} \n".format(dim))
else:
evaluateGradientDesc(data)
print("Explicit solution\n")
poly = PolynomialFeatures(dim)
z = poly.fit_transform(x)
theta = fitModel(z , y)
print("Intercept : {} \nCoefficients : {}\n".format(theta[0], theta[1:]))
testingError, sol = evaluateModel(z,y, False)
if(dim == 1):
print "Testing Error :", testingError
if (testingError < minTestingError):
minTestingError = testingError
optimalDimension = dim
optSol = sol
print "Optimal Dimension : {}, Testing Error : {} ".format(optimalDimension, minTestingError)
return optSol
开发者ID:rakeshadk7, 项目名称:MachineLearning, 代码行数:29, 代码来源:mvr.py
示例16: init_predict
def init_predict(mode):
""" 整理为用于预测的 X
i: features
o: X
"""
import scipy.io as sio
import scipy as sp
from sklearn.preprocessing import PolynomialFeatures
uid_ave = sio.loadmat('predict_cut_uid_ave.mat')['X']
poly = PolynomialFeatures(degree=2)
poly_uid_ave = poly.fit_transform(uid_ave)
combined_list = [sp.sparse.csc_matrix(poly_uid_ave)]
if mode == 'f':
X_words = sio.loadmat('predict_cut_Xf.mat')['X']
elif mode == 'c':
X_words = sio.loadmat('predict_cut_Xc.mat')['X']
else:
X_words = sio.loadmat('predict_cut_Xl.mat')['X']
#transformer = TfidfTransformer()
#X_tfidf = transformer.fit_transform(X_words)
combined_list.append(X_words)
X = sp.sparse.hstack(combined_list)
print(X.shape)
return X
开发者ID:organization-lab, 项目名称:weibo-predict, 代码行数:30, 代码来源:regressor.py
示例17: predict
def predict(self, x):
## as it is trained on polynominal features, we need to transform x
poly = PolynomialFeatures(degree=self.degree)
polynominal_features = poly.fit_transform(x)[0]
print polynominal_features.reshape
return self.model.predict(polynominal_features)
开发者ID:tempflip, 项目名称:fin_playground, 代码行数:7, 代码来源:blog_boston2.py
示例18: predict
def predict(self, X, coefs):
# first column of Z is time
# we will replace the other columns with regressed data
# clean-up from before
Z = self.X.copy()
print type(Z), Z.head()
print type(coefs), coefs.head()
poly = PolynomialFeatures(degree=self.n)
for trial_index, (coefficients, x) in enumerate(izip(coefs, Z)):
print trial_index, coefficients.shape, x.shape
# reshape required by t
t = poly.fit_transform((x[:,0]).reshape(-1,1))
# only regress on data past reference time
t = t[self.reference_time:]
z = np.zeros(x.shape)
# first column is time
z[:,0] = x[:,0]
# columns up to reference time are just 0 and were not regressed
z[:self.reference_time, 1:] = 0
# columns after reference_time were regressed with coefficients
print t.shape, z.shape, coefficients.shape
z[self.reference_time:, 1:] = np.dot(t, coefficients)
Z.iloc[trial_index] = z
return Z
开发者ID:fcesco, 项目名称:smelling_sepsis, 代码行数:27, 代码来源:featurizer.py
Python入门教程 Python 是一种解释型、面向对象、动态数据类型的高级程序设计语言。 P
阅读:13807| 2022-01-22
Python wikiutil.getFrontPage函数代码示例
阅读:10195| 2022-05-24
Python 简介 Python 是一个高层次的结合了解释性、编译性、互动性和面向对象的脚本
阅读:4091| 2022-01-22
Python tests.group函数代码示例
阅读:4043| 2022-05-27
Python util.check_if_user_has_permission函数代码示例
阅读:3845| 2022-05-27
Python 练习实例98 Python 100例题目:从键盘输入一个字符串,将小写字母全部转换成大
阅读:3514| 2022-01-22
Python 环境搭建 本章节我们将向大家介绍如何在本地搭建 Python 开发环境。 Py
阅读:3031| 2022-01-22
Python output.darkgreen函数代码示例
阅读:2653| 2022-05-25
Python 基础语法 Python 语言与 Perl,C 和 Java 等语言有许多相似之处。但是,也
阅读:2650| 2022-01-22
Python 中文编码前面章节中我们已经学会了如何用 Python 输出 Hello, World!,英文没
阅读:2302| 2022-01-22
请发表评论