def test_f_oneway_ints(): # Smoke test f_oneway on integers: that it does raise casting errors # with recent numpys X = np.random.randint(10, size=(10, 10)) y = np.arange(10) fint, pint = f_oneway(X, y) # test that is gives the same result as with float f, p = f_oneway(X.astype(np.float), y) assert_array_almost_equal(f, fint, decimal=5) assert_array_almost_equal(p, pint, decimal=5)
def test_f_oneway_ints(): # Smoke test f_oneway on integers: that it does raise casting errors # with recent numpys X = np.random.randint(10, size=(10, 10)) y = np.arange(10) fint, pint = f_oneway(X, y) # test that is gives the same result as with float f, p = f_oneway(X.astype(np.float), y) assert_array_equal(f, fint) assert_array_equal(p, pint)
def test_f_oneway_vs_scipy_stats(): """Test that our f_oneway gives the same result as scipy.stats""" X1 = np.random.randn(10, 3) X2 = 1 + np.random.randn(10, 3) f, pv = stats.f_oneway(X1, X2) f2, pv2 = f_oneway(X1, X2) assert_true(np.allclose(f, f2)) assert_true(np.allclose(pv, pv2))
def test_f_oneway_vs_scipy_stats(): # Test that our f_oneway gives the same result as scipy.stats rng = np.random.RandomState(0) X1 = rng.randn(10, 3) X2 = 1 + rng.randn(10, 3) f, pv = stats.f_oneway(X1, X2) f2, pv2 = f_oneway(X1, X2) assert_true(np.allclose(f, f2)) assert_true(np.allclose(pv, pv2))
def test_f_oneway_ints(): # Smoke test f_oneway on integers: that it does raise casting errors # with recent numpys f_oneway(np.random.randint(10, size=(10, 10)), np.arange(10))
import metric as mm LabelEncoder=preprocessing.LabelEncoder().fit_transform #将变量分为因子变量和数值变量分开讨论 label_numeric=np.array([np.issubdtype(X.dtypes[i],np.number) for i in range(X.shape[1])]) fscore_nonumeric=X.loc[:,~label_numeric].describe().T.assign(missing_pct=lambda x:(N-x['count'])/N) fscore_numeric=X.loc[:,label_numeric].describe().T.assign(missing_pct=lambda x:(N-x['count'])/N) for cc in fscore_nonumeric.index: fscore_nonumeric.loc[cc,'iv']=mm.info_value(X[cc],Y) f,p=fs.f_oneway(X.loc[:,label_numeric],Y) fscore_numeric['f_oneway']=f fscore_numeric['f_oneway_p']=p # 测试数据 training=np.random.choice([True,False],p=[0.8,0.2],size=N) # 建模 #X.loc[:,~label_numeric]=X.loc[:,~label_numeric].apply(LabelEncoder) X1=pd.get_dummies(X.loc[:,~label_numeric],drop_first=True) X2=pd.concat([X1,X.loc[:,label_numeric]],axis=1)