如何使用scikit-learn将数据转换为适合多类分类任务的格式?

我正在尝试使用scikit-learn对从eBay API获取的数据进行预测。我想知道将这些数据转换为适合scikit-learn进行多类分类问题的格式的最佳方法。scikit-learn网站上关于导入外部数据的唯一解释似乎是加载svmlight文件,如下所示:

http://scikit-learn.org/stable/datasets/

我想在多种算法上使用这些数据,而不仅仅是SVM。我使用以下代码将数据存储在一个dict对象中:

from ebaysdk.finding import Connection as Findingfrom requests.exceptions import ConnectionErrortry:    api = Finding(appid="my_app_id")    api_request = {'keywords': 'Samsung Galaxy S5 G900R4 16GB',     'itemFilter': [{'name': 'SoldItemsOnly', 'value': 'true'}], 'outputSelector': 'SellerInfo', 'GLOBAL-ID': 'EBAY-      GB'}    response = api.execute('findCompletedItems', api_request)    #print(response.dict())except ConnectionError as e:    print(e)    print(e.response.dict())

我在网上搜索了教程或关于如何进行此操作的解释,但我找不到任何有用的信息,这些信息详细说明了如何将数据转换为我需要的格式以及该格式具体需要什么。

请问有人能指导我是否应该使用svmlight文件来实现这一点,以及如何操作,或者是否有其他导入数据的建议?我对机器学习、Python和scikit-learn都是新手,所以任何帮助都非常感激。

以下是原始数据格式的一个示例:

{'autoPay': 'true',  'condition': {'conditionDisplayName': 'Used', 'conditionId': '3000'},  'country': 'US',  'galleryURL': 'http://thumbs4.ebaystatic.com/m/mO-HwGeodkgYX6sRbPyFsrg/140.jpg',  'globalId': 'EBAY-US',  'isMultiVariationListing': 'false',  'itemId': '201265198351',  'listingInfo': {'bestOfferEnabled': 'false',   'buyItNowAvailable': 'false',   'endTime': '2015-01-16T00:23:19.000Z',   'gift': 'false',   'listingType': 'StoreInventory',   'startTime': '2015-01-15T15:47:38.000Z'},  'location': 'Dandridge,TN,USA',  'paymentMethod': 'PayPal',  'postalCode': '37725',  'primaryCategory': {'categoryId': '9355',   'categoryName': 'Cell Phones & Smartphones'},  'productId': {'_type': 'ReferenceID', 'value': '182557948'},  'returnsAccepted': 'true',  'sellerInfo': {'feedbackRatingStar': 'Turquoise',   'feedbackScore': '445',   'positiveFeedbackPercent': '100.0',   'sellerUserName': 'dadscritter15'},  'sellingStatus': {'convertedCurrentPrice': {'_currencyId': 'USD',    'value': '279.99'},   'currentPrice': {'_currencyId': 'USD', 'value': '279.99'},   'sellingState': 'Ended'},  'shippingInfo': {'expeditedShipping': 'true',   'handlingTime': '2',   'oneDayShippingAvailable': 'false',   'shipToLocations': ['US',    'CA',    'GB',    'AU',    'AT',    'BE',    'FR',    'DE',    'IT',    'JP',    'ES',    'CH',    'NL',    'CN',    'HK',    'MX'],   'shippingServiceCost': {'_currencyId': 'USD', 'value': '0.0'},   'shippingType': 'FlatDomesticCalculatedInternational'},  'title': 'Samsung Galaxy S5 SM-G900R4 (Latest Model) 16GB White (U.S. Cellular) Verify ESN',  'topRatedListing': 'false',  'viewItemURL': 'http://www.ebay.com/itm/Samsung-Galaxy-S5-SM-G900R4-Latest-Model-16GB-White-U-S-Cellular-Verify-ESN-/201265198351?pt=LH_DefaultDomain_0'}, {'autoPay': 'true',  'condition': {'conditionDisplayName': 'Used', 'conditionId': '3000'},  'country': 'US',  'galleryURL': 'http://thumbs4.ebaystatic.com/m/mO-HwGeodkgYX6sRbPyFsrg/140.jpg',  'globalId': 'EBAY-US',  'isMultiVariationListing': 'false',  'itemId': '201265198351',  'listingInfo': {'bestOfferEnabled': 'false',   'buyItNowAvailable': 'false',   'endTime': '2015-01-16T00:23:19.000Z',   'gift': 'false',   'listingType': 'StoreInventory',   'startTime': '2015-01-15T15:47:38.000Z'},  'location': 'Dandridge,TN,USA',  'paymentMethod': 'PayPal',  'postalCode': '37725',  'primaryCategory': {'categoryId': '9355',   'categoryName': 'Cell Phones & Smartphones'},  'productId': {'_type': 'ReferenceID', 'value': '182557948'},  'returnsAccepted': 'true',  'sellerInfo': {'feedbackRatingStar': 'Turquoise',   'feedbackScore': '445',   'positiveFeedbackPercent': '100.0',   'sellerUserName': 'dadscritter15'},  'sellingStatus': {'convertedCurrentPrice': {'_currencyId': 'USD',    'value': '279.99'},   'currentPrice': {'_currencyId': 'USD', 'value': '279.99'},   'sellingState': 'Ended'},  'shippingInfo': {'expeditedShipping': 'true',   'handlingTime': '2',   'oneDayShippingAvailable': 'false',   'shipToLocations': ['US',    'CA',    'GB',    'AU',    'AT',    'BE',    'FR',    'DE',    'IT',    'JP',    'ES',    'CH',    'NL',    'CN',    'HK',    'MX'],   'shippingServiceCost': {'_currencyId': 'USD', 'value': '0.0'},   'shippingType': 'FlatDomesticCalculatedInternational'},  'title': 'Samsung Galaxy S5 SM-G900R4 (Latest Model) 16GB White (U.S. Cellular) Verify ESN',  'topRatedListing': 'false',  'viewItemURL': 'http://www.ebay.com/itm/Samsung-Galaxy-S5-SM-G900R4-Latest-Model-16GB-White-U-S-Cellular-Verify-ESN-/201265198351?pt=LH_DefaultDomain_0'}

回答:

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注