У меня есть следующий список и массив numpy: Для списка:
features = np.array(X_train.columns).tolist()
results :
['Attr1', 'Attr2', 'Attr3', 'Attr4', 'Attr5', 'Attr6', 'Attr7', 'Attr8', 'Attr9', 'Attr10', 'Attr11', 'Attr12', 'Attr13', 'Attr14', 'Attr15', 'Attr16', 'Attr17', 'Attr18', 'Attr19', 'Attr20', 'Attr21', 'Attr22', 'Attr23', 'Attr24', 'Attr25', 'Attr26', 'Attr27', 'Attr28', 'Attr29', 'Attr30', 'Attr31', 'Attr32', 'Attr33', 'Attr34', 'Attr35', 'Attr36', 'Attr37', 'Attr38', 'Attr39', 'Attr40', 'Attr41', 'Attr42', 'Attr43', 'Attr44', 'Attr45', 'Attr46', 'Attr47', 'Attr48', 'Attr49', 'Attr50', 'Attr51', 'Attr52', 'Attr53', 'Attr54', 'Attr55', 'Attr56', 'Attr57', 'Attr58', 'Attr59', 'Attr60', 'Attr61', 'Attr62', 'Attr63', 'Attr64']
и имя массива ab
aa=(lr.coef_) #I put a regression result on numpy array so I can split them, I want to put them as a list
ab=np.split(aa,len(aa))
results :
[array([[ 0.04181571, 0.62369216, -0.23559375, 0.78663624, -0.13935947,
-0.1118698 , -0.05672835, -1.73851643, -0.42134655, 0.79001534,
0.05048936, -0.09287526, 0.10103251, -0.0587092 , -0.05300849,
0.72827807, 1.15870475, -0.13861187, -0.42572654, 0.19369654,
-0.33319238, -0.06805035, 0.14067888, -0.07418516, -0.04400882,
-0.78701564, -0.10921816, -0.26166642, 0.06800944, 0.07672145,
0.22109349, -0.15389544, 2.41697614, 0.21749429, -0.0766771 ,
0.77580103, 0.04128744, -0.92835969, -0.41802274, 0.89865658,
-0.12102089, -0.28887104, 0.10421332, 0.14445757, 0.02719274,
-1.73622976, -0.34980593, 0.35199196, 0.56110135, 0.4460968 ,
-1.13265322, 0.26188587, 0.14336352, 0.2341355 , -0.10077637,
0.43080231, -0.05521557, -0.1996818 , 0.00513076, -0.14477274,
0.04712721, 0.15380395, -2.51974007, -0.03988658]])]
Теперь я хочу создать словарь для их, но здесь я запутался, как мне превратить массив в список.
Вот что я сделал:
for x in features :
for y in ab:
print({x:y})
and the result is not as desired, since it's failed to break down the array :
{'Attr1': array([[ 0.04181571, 0.62369216, -0.23559375, 0.78663624, -0.13935947,
-0.1118698 , -0.05672835, -1.73851643, -0.42134655, 0.79001534,
0.05048936, -0.09287526, 0.10103251, -0.0587092 , -0.05300849,
0.72827807, 1.15870475, -0.13861187, -0.42572654, 0.19369654,
-0.33319238, -0.06805035, 0.14067888, -0.07418516, -0.04400882,
-0.78701564, -0.10921816, -0.26166642, 0.06800944, 0.07672145,
0.22109349, -0.15389544, 2.41697614, 0.21749429, -0.0766771 ,
0.77580103, 0.04128744, -0.92835969, -0.41802274, 0.89865658,
-0.12102089, -0.28887104, 0.10421332, 0.14445757, 0.02719274,
-1.73622976, -0.34980593, 0.35199196, 0.56110135, 0.4460968 ,
-1.13265322, 0.26188587, 0.14336352, 0.2341355 , -0.10077637,
0.43080231, -0.05521557, -0.1996818 , 0.00513076, -0.14477274,
0.04712721, 0.15380395, -2.51974007, -0.03988658]])}
{'Attr2': array([[ 0.04181571, 0.62369216, -0.23559375, 0.78663624, -0.13935947,
-0.1118698 , -0.05672835, -1.73851643, -0.42134655, 0.79001534,
0.05048936, -0.09287526, 0.10103251, -0.0587092 , -0.05300849,
0.72827807, 1.15870475, -0.13861187, -0.42572654, 0.19369654,
-0.33319238, -0.06805035, 0.14067888, -0.07418516, -0.04400882,
-0.78701564, -0.10921816, -0.26166642, 0.06800944, 0.07672145,
0.22109349, -0.15389544, 2.41697614, 0.21749429, -0.0766771 ,
0.77580103, 0.04128744, -0.92835969, -0.41802274, 0.89865658,
-0.12102089, -0.28887104, 0.10421332, 0.14445757, 0.02719274,
-1.73622976, -0.34980593, 0.35199196, 0.56110135, 0.4460968 ,
-1.13265322, 0.26188587, 0.14336352, 0.2341355 , -0.10077637,
0.43080231, -0.05521557, -0.1996818 , 0.00513076, -0.14477274,
0.04712721, 0.15380395, -2.51974007, -0.03988658]])}
{'Attr3': array([[ 0.04181571, 0.62369216, -0.23559375, 0.78663624, -0.13935947,
-0.1118698 , -0.05672835, -1.73851643, -0.42134655, 0.79001534,
0.05048936, -0.09287526, 0.10103251, -0.0587092 , -0.05300849,
0.72827807, 1.15870475, -0.13861187, -0.42572654, 0.19369654,
-0.33319238, -0.06805035, 0.14067888, -0.07418516, -0.04400882,
-0.78701564, -0.10921816, -0.26166642, 0.06800944, 0.07672145,
0.22109349, -0.15389544, 2.41697614, 0.21749429, -0.0766771 ,
0.77580103, 0.04128744, -0.92835969, -0.41802274, 0.89865658,
-0.12102089, -0.28887104, 0.10421332, 0.14445757, 0.02719274,
-1.73622976, -0.34980593, 0.35199196, 0.56110135, 0.4460968 ,
-1.13265322, 0.26188587, 0.14336352, 0.2341355 , -0.10077637,
0.43080231, -0.05521557, -0.1996818 , 0.00513076, -0.14477274,
0.04712721, 0.15380395, -2.51974007, -0.03988658]])}.......
Не могли бы вы помочь мне составить список для ab
массив? И как мне превратить их в словарь?
Th expected results : {[Attr1 : 0.04181571], Attr2 : 0.623692160, and so on...}
Большое спасибо!