__init\uuuu()获得意外的关键字参数“handle\u unknown”

2024-05-03 11:24:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用sklearn对我的分类特征进行顺序编码,但在编译以下代码时,我得到了错误__init__() got an unexpected keyword argument 'handle_unknown'

  oe_l = OrdinalEncoder(handle_unknown ='use_encoded_value',unknown_value = -1)
  oe_y = OrdinalEncoder(handle_unknown ='use_encoded_value', unknown_value = -1)

  oe_l.fit(train_d['Language'])
  oe_y.fit(train_d['Year'])

  train_d['Language'] = oe_l.transform(train_d['Language'])
  test_d['Language'] = oe_l.transform(test_d['Language'])

  train_d['Year'] = oe_y.transform(train_d['Year'])
  test_d['Year'] = oe_y.transform(test_d['Year'])

用于再现错误的示例数据:

df = {'Abstract': {0: 'The present study investigates an inventory model for non-instantaneous deteriorating items under inflationary conditions with partially backlogged shortages. In today’s market structure consumers are looking for goods for which there is a delay in deterioration. At the same time, the consumers’ willingness to wait has been decreased over time, which leads to lost sales. Moreover in financial decision-making, the effects of inflation and time value of money cannot be oblivious to an inventory system. In this scenario, managing inventory of goods remains a challenging task for the decision makers, who may also have to rent warehouse under different prevailing factors such as, bulk discount, limited space in the retail outlet, or increasing inflation rates. With a focus on reduction of costs and increasing customer service, warehouse decision models are crucial for an organization’s profitability. Hence a mathematical model has been developed in the view of above scenario, in order to determine the optimal policy for the decision maker, by minimizing the present worth of total cost. The optimization procedure has been illustrated by a numerical example and detailed sensitivity analysis of the optimal solution has been performed to showcase the effect of various parameters. Managerial implications has also been presented to aid the decision making process.\r\n',
  1: 'AIM: To investigate the clinical characteristics and surgical treatment fororbital wall fracture of soldiers. METHODS: This study choose 58 soldiers(58 eyes)who had surgical treatments for orbital wall fracture in our hospital from January 1st, 2015 to December 31st, 2018. Their demographic characteristics, causes of injury, fracture sites, preoperative and postoperative visual acuity, eye movement, eye prominence, and operative conditions were recorded and statistically analyzed. The patients were followed up for 6mo after treatment. RESULTS: All patients in 58 cases of orbital wall fractures were male. The P50 age of them was 21, and most of them were 20-29 years old(78%). 45 cases(78%)were injured at work, in which boxing injury and impingement injury were the main causes(74%). Simple medial orbital wall, inferior wall and both of the medial and inferior wall fractures were the common types(91%). The visual acuity of all the patients did not change significantly after operation comparing with preoperative visual acuity. According to the clinical data of postoperative CT and postoperative follow up, no implant displacement, infection or other serious complications appeared. Eye movement disorder of 33 patients were improved. Abnormal suborbital perception of 7 patients disappeared. And enophthalmos of 3 patients were corrected. CONCLUSION: Young male soldiers are the main population of orbital wall fracture. It is of great significance to improve the protection in daily training. Surgical treatment for orbital wall fractures has significant therapeutic effect. Furthermore, it is very necessary for primary hospital to develop basic diagnosis and treatment.',
  2: 'Aflatoxin M1 (AFM1) and ochratoxin A (OTA), which widely coexist in milk, may pose a serious threat to human health. Mucin is a major component of the intestinal mucus layer, which plays an important role in maintaining intestinal mucosal homeostasis. However, the effect of mycotoxins AFM1 and OTA on intestinal mucin production is still not clear. This study aimed to investigate individual and interactive effects of mycotoxins AFM1 and OTA on the intestinal barrier and the mRNA expression of intestinal mucin (MUC2, MUC5AC and MUC5B) and on protein production in Caco-2/HT29-MTX cultures after 48 h of exposure. Our results show that individual mycotoxins and their mixtures significantly reduced intestinal cell viability and transepithelial electrical resistance (TEER) values, as well as significantly altered intestinal mucin mRNA expression and protein abundance. Moreover, OTA showed toxicity similar to AFM1 in cell viability and TEER value at the same concentration. When the two mycotoxins acted in combination, the synergistic effects observed in the assessment of cell viability and protein abundance in all mono- and co-cultures. In general, this study provides evidence that AFM1 and OTA can damage the intestine, and it contributes to optimized maximum permissible limits of mycotoxins in milk.',
  3: 'Background/Aim: There are still unrevealed treasures of traditional dental medicine that are the reason to investigate and present various ways in treatment of oral and orofacial tissues as well as magic and religious elements involved in representative areas among Serbs. Methods: Information was collected from the elderly non-professional folk dentists and herbalists with additional help from local physicians and dentists that was done through questionnaire and personal interviews. Results: Classified and prepared material consists of total 1038 enquiry sheets. The 41 data were averagely obtained by inquiry form i.e. 41984 information for the whole research. The most voluminous was group of 64 recipes: gums diseases 39 and toothache 25 while only seven for magic way of treatment. Among them 18 prescriptions were of non-herbal origin. The study revealed 84 herbal original prescriptions including 67 plant species (29 families) including local name, synonyms and preparation mode. Traditional healers used predominantly herbal recipes to treatpainful tooth, gum disease, blisters - herpetic ulcers /lips and mouth/, stomatitis /painful mouth, ptyalismus/, maxillary sinusitis, bad breath, teeth cleaning and bleaching. Very few methods of treatment appeared as inadequate (magical practice), whereas majority were noted as beneficial ones (herbal medicine). Still many people in distant non-urban areas use various plant recipes especially as the first aid in oral disease healing. Conclusions: The significance of plants obtained from unpolluted areas whose active ingredients have not yet been used in dental pharmaceutics should be investigated further. \n\nKEY WORDS: medicinal plants, ethnomedicine, dental ethnopharmacology, traditional dentistry, phytotherapy [J Complement Med Res 2017; 6(2.000): 223-233]',
  4: 'Impairment in empathy has been demonstrated in patients with schizophrenia and individuals with psychosis proneness. In the present study, we examined the neural correlates underlying theory of mind (ToM) and empathy and the relationships between these two social cognitive abilities with schizotypy. Fifty-six first-year college students (31 males, 25 females) between 17 and 21 years of age (M = 19.3, SD = 0.9) from a medical university in China participated. All participants undertook a comic strips functional imaging task that specifically examined both empathy and ToM. In addition, they completed two self-report scales: the Chapman Psychosis Proneness scale and the Interpersonal Responsivity Index (IRI). Results showed that both empathy and ToM conditions of the task were associated with brain activity in the middle temporal gyrus, the temporo-parietal junction (TPJ), the precuneus, and the posterior cingulate gyrus. In addition, we found positive correlations between negative schizotypy and brain activity in regions involved in social cognition, namely, the middle temporal gyrus, the TPJ, as well as the medial prefrontal gyrus. These findings highlight that different dimensions of schizotypy may show different associations with brain regions involved in social cognitive abilities. More importantly, the positive correlation between brain activity and anhedonia suggests the presence of compensatory mechanisms in high-risk populations.'},
 'Language': {0: 'en', 1: 'en', 2: 'en', 3: 'en', 4: 'en'},
 'Title': {0: 'Replenishment policy for non-instantaneous deteriorating items in a two storage facilities under inflationary conditions ',
  1: "Analysis of soldiers' orbital wall fracture surgical treatment in General Hospital of Northen Theater Command",
  2: 'Modulation of Mucin (MUC2, MUC5AC and MUC5B) mRNA Expression and Protein Production and Secretion in Caco-2/HT29-MTX Co-Cultures Following Exposure to Individual and Combined Aflatoxin M1 and Ochratoxin A',
  3: 'Traditional dentistry knowledge among Serbs in several Balkan countries',
  4: 'Dimensional schizotypy and social cognition: An fMRI imaging study'},
 'Year': {0: 2016, 1: 2019, 2: 2019, 3: 2017, 4: 2015},
 'id': {0: 1, 1: 2, 2: 3, 3: 4, 4: 5},
 'total_rel_score': {0: 0.6306818182,
  1: 0.5833333333,
  2: 0.3722222222,
  3: 0.6617647059,
  4: 0.3737373737}}

有人能告诉我我的密码出了什么问题吗


Tags: andofthetoinforaswith
2条回答

您很可能没有使用适当版本的scikit-learn

handle_unknownunknown_value随着版本0.24.0的发布而添加到OrdinalEncoder(参见release history

检查scikit-learn的版本,必要时进行升级

关于您的问题,您的代码运行良好。另外,我刚刚在传球时对他们进行了重塑,这样他们就不会出现失误

# Here df is the df shared by you
df = pd.DataFrame().from_dict(df)

oe_l = OrdinalEncoder(handle_unknown ='use_encoded_value',unknown_value = -1)
oe_y = OrdinalEncoder(handle_unknown ='use_encoded_value', unknown_value = -1)

oe_l.fit(df['Language'].values.reshape(-1,1))
oe_y.fit(df['Year'].values.reshape(-1,1))

df['Language'] = oe_l.transform(df['Language'].values.reshape(-1,1))

df['Year'] = oe_y.transform(df['Year'].values.reshape(-1,1))

我的sklearn版本-0.24.2。说到这里,你应该做些什么

  1. 转到cmd(命令提示/Python提示)或终端
  2. 激活您的环境(在cmd和终端的情况下)
  3. 粘贴并输入pip install -U scikit-learn 如果您不使用“虚拟环境”,则无需执行第二步

相关问题 更多 >