@ParulSinha wrote:
Hi,
How can I use poly function in R(or any other solution),given a dataframe as input to generate two way interaction only and also do normalization.
To brief : I was working on imbalanced classification with AV’s ‘HR Analytic’ practice problem
After multiple failed attempts, I checked the top solution provided(in python) and realized the only and important difference was the winner had 'done two way interactions followed by normalization '.
I tried to do the same in ‘R’ -interaction using model.matrix, followed by prep_num (center,scale) to do normalization . model matrix did generate interactions and increased no. of columns from 54 to 850, but when I tried to do normalization , it failed giving error ‘cannot create memory of …’
Please help with a smarter one line solution,for the corresponding python code (winning solution) -
Y = dfmerged.is_promoted
X = dfmerged.drop([‘is_promoted’],1)def add_interactions(df):
combos = list(combinations(list(df.columns), 2))
colnames = list(df.columns)+[’_’.join(x) for x in combos]#scaler = MinMaxScaler() #scaler.fit(df) #df = scaler.transform(df) poly = PolynomialFeatures(interaction_only=True, include_bias=False) df = poly.fit_transform(df) df = pd.DataFrame(df) df.columns = colnames noint_indices = [i for i,x in enumerate(list((df==0).all())) if x] df= df.drop(df.columns[noint_indices], axis=1) return dfX = add_interactions(X)
X.shape(I hope the above python code generates interactions followed by normalization)
Posts: 1
Participants: 1