我正在尝试使用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'}
回答: