This question already has answers here:
Convert a bytes array into JSON format
(8 answers)
Closed 3 months ago.
I have a variable like this:
result = b'{"Results": {"WebServiceOutput0": [{"Label": 7.0, "f0": 0.0, "f1": 0.0, "f2": 0.0, "f3": 0.0, "f4": 0.0, "f5": 0.0, "f6": 0.0, "f7": 0.0, "f8": 0.0, "f9": 0.0, "f10": 0.0, "f11": 0.0, "f12": 0.0, "f13": 0.0, "f14": 0.0, "f15": 0.0, "f16": 0.0, "f17": 0.0, "f18": 0.0, "f19": 0.0, "f20": 0.0, "f21": 0.0, "f22": 0.0, "f23": 0.0, "f24": 0.0, "f25": 0.0, "f26": 0.0, "f27": 0.0, "f28": 0.0, "f29": 0.0, "f30": 0.0, "f31": 0.0, "f32": 0.0, "f33": 0.0, "f34": 0.0, "f35": 0.0, "f36": 0.0, "f37": 0.0, "f38": 0.0, "f39": 0.0, "f40": 0.0, "f41": 0.0, "f42": 0.0, "f43": 0.0, "f44": 0.0, "f45": 0.0, "f46": 0.0, "f47": 0.0, "f48": 0.0, "f49": 0.0, "f50": 0.0, "f51": 0.0, "f52": 0.0, "f53": 0.0, "f54": 0.0, "f55": 0.0, "f56": 0.0, "f57": 0.0, "f58": 0.0, "f59": 0.0, "f60": 0.0, "f61": 0.0, "f62": 0.0, "f63": 0.0, "f64": 0.0, "f65": 0.0, "f66": 0.0, "f67": 0.0, "f68": 0.0, "f69": 0.0, "f70": 0.0, "f71": 0.0, "f72": 0.0, "f73": 0.0, "f74": 0.0, "f75": 0.0, "f76": 0.0, "f77": 0.0, "f78": 0.0, "f79": 0.0, "f80": 0.0, "f81": 0.0, "f82": 0.0, "f83": 0.0, "f84": 0.0, "f85": 0.0, "f86": 0.0, "f87": 0.0, "f88": 0.0, "f89": 0.0, "f90": 0.0, "f91": 0.0, "f92": 0.0, "f93": 0.0, "f94": 0.0, "f95": 0.0, "f96": 0.0, "f97": 0.0, "f98": 0.0, "f99": 0.0, "f100": 0.0, "f101": 0.0, "f102": 0.0, "f103": 0.0, "f104": 0.0, "f105": 0.0, "f106": 0.0, "f107": 0.0, "f108": 0.0, "f109": 0.0, "f110": 0.0, "f111": 0.0, "f112": 0.0, "f113": 0.0, "f114": 0.0, "f115": 0.0, "f116": 0.0, "f117": 0.0, "f118": 0.0, "f119": 0.0, "f120": 0.0, "f121": 0.0, "f122": 0.0, "f123": 0.0, "f124": 0.0, "f125": 0.0, "f126": 0.0, "f127": 0.0, "f128": 0.0, "f129": 0.0, "f130": 0.0, "f131": 0.0, "f132": 0.0, "f133": 0.0, "f134": 0.0, "f135": 0.0, "f136": 0.0, "f137": 0.0, "f138": 0.0, "f139": 0.0, "f140": 0.0, "f141": 0.0, "f142": 0.0, "f143": 0.0, "f144": 0.0, "f145": 0.0, "f146": 0.0, "f147": 0.0, "f148": 0.0, "f149": 0.0, "f150": 0.0, "f151": 0.0, "f152": 0.0, "f153": 0.0, "f154": 0.0, "f155": 0.0, "f156": 0.0, "f157": 0.0, "f158": 0.0, "f159": 0.0, "f160": 0.0, "f161": 0.0, "f162": 0.0, "f163": 0.0, "f164": 0.0, "f165": 0.0, "f166": 0.0, "f167": 0.0, "f168": 0.0, "f169": 0.0, "f170": 0.0, "f171": 0.0, "f172": 0.0, "f173": 0.0, "f174": 0.0, "f175": 0.0, "f176": 0.0, "f177": 0.0, "f178": 0.0, "f179": 0.0, "f180": 0.0, "f181": 0.0, "f182": 0.0, "f183": 0.0, "f184": 0.0, "f185": 0.0, "f186": 0.0, "f187": 0.0, "f188": 0.0, "f189": 0.0, "f190": 0.0, "f191": 0.0, "f192": 0.0, "f193": 0.0, "f194": 0.0, "f195": 0.0, "f196": 0.0, "f197": 0.0, "f198": 0.0, "f199": 0.0, "f200": 0.0, "f201": 0.0, "f202": 84.0, "f203": 185.0, "f204": 159.0, "f205": 151.0, "f206": 60.0, "f207": 36.0, "f208": 0.0, "f209": 0.0, "f210": 0.0, "f211": 0.0, "f212": 0.0, "f213": 0.0, "f214": 0.0, "f215": 0.0, "f216": 0.0, "f217": 0.0, "f218": 0.0, "f219": 0.0, "f220": 0.0, "f221": 0.0, "f222": 0.0, "f223": 0.0, "f224": 0.0, "f225": 0.0, "f226": 0.0, "f227": 0.0, "f228": 0.0, "f229": 0.0, "f230": 222.0, "f231": 254.0, "f232": 254.0, "f233": 254.0, "f234": 254.0, "f235": 241.0, "f236": 198.0, "f237": 198.0, "f238": 198.0, "f239": 198.0, "f240": 198.0, "f241": 198.0, "f242": 198.0, "f243": 198.0, "f244": 170.0, "f245": 52.0, "f246": 0.0, "f247": 0.0, "f248": 0.0, "f249": 0.0, "f250": 0.0, "f251": 0.0, "f252": 0.0, "f253": 0.0, "f254": 0.0, "f255": 0.0, "f256": 0.0, "f257": 0.0, "f258": 67.0, "f259": 114.0, "f260": 72.0, "f261": 114.0, "f262": 163.0, "f263": 227.0, "f264": 254.0, "f265": 225.0, "f266": 254.0, "f267": 254.0, "f268": 254.0, "f269": 250.0, "f270": 229.0, "f271": 254.0, "f272": 254.0, "f273": 140.0, "f274": 0.0, "f275": 0.0, "f276": 0.0, "f277": 0.0, "f278": 0.0, "f279": 0.0, "f280": 0.0, "f281": 0.0, "f282": 0.0, "f283": 0.0, "f284": 0.0, "f285": 0.0, "f286": 0.0, "f287": 0.0, "f288": 0.0, "f289": 0.0, "f290": 0.0, "f291": 17.0, "f292": 66.0, "f293": 14.0, "f294": 67.0, "f295": 67.0, "f296": 67.0, "f297": 59.0, "f298": 21.0, "f299": 236.0, "f300": 254.0, "f301": 106.0, "f302": 0.0, "f303": 0.0, "f304": 0.0, "f305": 0.0, "f306": 0.0, "f307": 0.0, "f308": 0.0, "f309": 0.0, "f310": 0.0, "f311": 0.0, "f312": 0.0, "f313": 0.0, "f314": 0.0, "f315": 0.0, "f316": 0.0, "f317": 0.0, "f318": 0.0, "f319": 0.0, "f320": 0.0, "f321": 0.0, "f322": 0.0, "f323": 0.0, "f324": 0.0, "f325": 0.0, "f326": 83.0, "f327": 253.0, "f328": 209.0, "f329": 18.0, "f330": 0.0, "f331": 0.0, "f332": 0.0, "f333": 0.0, "f334": 0.0, "f335": 0.0, "f336": 0.0, "f337": 0.0, "f338": 0.0, "f339": 0.0, "f340": 0.0, "f341": 0.0, "f342": 0.0, "f343": 0.0, "f344": 0.0, "f345": 0.0, "f346": 0.0, "f347": 0.0, "f348": 0.0, "f349": 0.0, "f350": 0.0, "f351": 0.0, "f352": 0.0, "f353": 22.0, "f354": 233.0, "f355": 255.0, "f356": 83.0, "f357": 0.0, "f358": 0.0, "f359": 0.0, "f360": 0.0, "f361": 0.0, "f362": 0.0, "f363": 0.0, "f364": 0.0, "f365": 0.0, "f366": 0.0, "f367": 0.0, "f368": 0.0, "f369": 0.0, "f370": 0.0, "f371": 0.0, "f372": 0.0, "f373": 0.0, "f374": 0.0, "f375": 0.0, "f376": 0.0, "f377": 0.0, "f378": 0.0, "f379": 0.0, "f380": 0.0, "f381": 129.0, "f382": 254.0, "f383": 238.0, "f384": 44.0, "f385": 0.0, "f386": 0.0, "f387": 0.0, "f388": 0.0, "f389": 0.0, "f390": 0.0, "f391": 0.0, "f392": 0.0, "f393": 0.0, "f394": 0.0, "f395": 0.0, "f396": 0.0, "f397": 0.0, "f398": 0.0, "f399": 0.0, "f400": 0.0, "f401": 0.0, "f402": 0.0, "f403": 0.0, "f404": 0.0, "f405": 0.0, "f406": 0.0, "f407": 0.0, "f408": 59.0, "f409": 249.0, "f410": 254.0, "f411": 62.0, "f412": 0.0, "f413": 0.0, "f414": 0.0, "f415": 0.0, "f416": 0.0, "f417": 0.0, "f418": 0.0, "f419": 0.0, "f420": 0.0, "f421": 0.0, "f422": 0.0, "f423": 0.0, "f424": 0.0, "f425": 0.0, "f426": 0.0, "f427": 0.0, "f428": 0.0, "f429": 0.0, "f430": 0.0, "f431": 0.0, "f432": 0.0, "f433": 0.0, "f434": 0.0, "f435": 0.0, "f436": 133.0, "f437": 254.0, "f438": 187.0, "f439": 5.0, "f440": 0.0, "f441": 0.0, "f442": 0.0, "f443": 0.0, "f444": 0.0, "f445": 0.0, "f446": 0.0, "f447": 0.0, "f448": 0.0, "f449": 0.0, "f450": 0.0, "f451": 0.0, "f452": 0.0, "f453": 0.0, "f454": 0.0, "f455": 0.0, "f456": 0.0, "f457": 0.0, "f458": 0.0, "f459": 0.0, "f460": 0.0, "f461": 0.0, "f462": 0.0, "f463": 9.0, "f464": 205.0, "f465": 248.0, "f466": 58.0, "f467": 0.0, "f468": 0.0, "f469": 0.0, "f470": 0.0, "f471": 0.0, "f472": 0.0, "f473": 0.0, "f474": 0.0, "f475": 0.0, "f476": 0.0, "f477": 0.0, "f478": 0.0, "f479": 0.0, "f480": 0.0, "f481": 0.0, "f482": 0.0, "f483": 0.0, "f484": 0.0, "f485": 0.0, "f486": 0.0, "f487": 0.0, "f488": 0.0, "f489": 0.0, "f490": 0.0, "f491": 126.0, "f492": 254.0, "f493": 182.0, "f494": 0.0, "f495": 0.0, "f496": 0.0, "f497": 0.0, "f498": 0.0, "f499": 0.0, "f500": 0.0, "f501": 0.0, "f502": 0.0, "f503": 0.0, "f504": 0.0, "f505": 0.0, "f506": 0.0, "f507": 0.0, "f508": 0.0, "f509": 0.0, "f510": 0.0, "f511": 0.0, "f512": 0.0, "f513": 0.0, "f514": 0.0, "f515": 0.0, "f516": 0.0, "f517": 0.0, "f518": 75.0, "f519": 251.0, "f520": 240.0, "f521": 57.0, "f522": 0.0, "f523": 0.0, "f524": 0.0, "f525": 0.0, "f526": 0.0, "f527": 0.0, "f528": 0.0, "f529": 0.0, "f530": 0.0, "f531": 0.0, "f532": 0.0, "f533": 0.0, "f534": 0.0, "f535": 0.0, "f536": 0.0, "f537": 0.0, "f538": 0.0, "f539": 0.0, "f540": 0.0, "f541": 0.0, "f542": 0.0, "f543": 0.0, "f544": 0.0, "f545": 19.0, "f546": 221.0, "f547": 254.0, "f548": 166.0, "f549": 0.0, "f550": 0.0, "f551": 0.0, "f552": 0.0, "f553": 0.0, "f554": 0.0, "f555": 0.0, "f556": 0.0, "f557": 0.0, "f558": 0.0, "f559": 0.0, "f560": 0.0, "f561": 0.0, "f562": 0.0, "f563": 0.0, "f564": 0.0, "f565": 0.0, "f566": 0.0, "f567": 0.0, "f568": 0.0, "f569": 0.0, "f570": 0.0, "f571": 0.0, "f572": 3.0, "f573": 203.0, "f574": 254.0, "f575": 219.0, "f576": 35.0, "f577": 0.0, "f578": 0.0, "f579": 0.0, "f580": 0.0, "f581": 0.0, "f582": 0.0, "f583": 0.0, "f584": 0.0, "f585": 0.0, "f586": 0.0, "f587": 0.0, "f588": 0.0, "f589": 0.0, "f590": 0.0, "f591": 0.0, "f592": 0.0, "f593": 0.0, "f594": 0.0, "f595": 0.0, "f596": 0.0, "f597": 0.0, "f598": 0.0, "f599": 0.0, "f600": 38.0, "f601": 254.0, "f602": 254.0, "f603": 77.0, "f604": 0.0, "f605": 0.0, "f606": 0.0, "f607": 0.0, "f608": 0.0, "f609": 0.0, "f610": 0.0, "f611": 0.0, "f612": 0.0, "f613": 0.0, "f614": 0.0, "f615": 0.0, "f616": 0.0, "f617": 0.0, "f618": 0.0, "f619": 0.0, "f620": 0.0, "f621": 0.0, "f622": 0.0, "f623": 0.0, "f624": 0.0, "f625": 0.0, "f626": 0.0, "f627": 31.0, "f628": 224.0, "f629": 254.0, "f630": 115.0, "f631": 1.0, "f632": 0.0, "f633": 0.0, "f634": 0.0, "f635": 0.0, "f636": 0.0, "f637": 0.0, "f638": 0.0, "f639": 0.0, "f640": 0.0, "f641": 0.0, "f642": 0.0, "f643": 0.0, "f644": 0.0, "f645": 0.0, "f646": 0.0, "f647": 0.0, "f648": 0.0, "f649": 0.0, "f650": 0.0, "f651": 0.0, "f652": 0.0, "f653": 0.0, "f654": 0.0, "f655": 133.0, "f656": 254.0, "f657": 254.0, "f658": 52.0, "f659": 0.0, "f660": 0.0, "f661": 0.0, "f662": 0.0, "f663": 0.0, "f664": 0.0, "f665": 0.0, "f666": 0.0, "f667": 0.0, "f668": 0.0, "f669": 0.0, "f670": 0.0, "f671": 0.0, "f672": 0.0, "f673": 0.0, "f674": 0.0, "f675": 0.0, "f676": 0.0, "f677": 0.0, "f678": 0.0, "f679": 0.0, "f680": 0.0, "f681": 0.0, "f682": 61.0, "f683": 242.0, "f684": 254.0, "f685": 254.0, "f686": 52.0, "f687": 0.0, "f688": 0.0, "f689": 0.0, "f690": 0.0, "f691": 0.0, "f692": 0.0, "f693": 0.0, "f694": 0.0, "f695": 0.0, "f696": 0.0, "f697": 0.0, "f698": 0.0, "f699": 0.0, "f700": 0.0, "f701": 0.0, "f702": 0.0, "f703": 0.0, "f704": 0.0, "f705": 0.0, "f706": 0.0, "f707": 0.0, "f708": 0.0, "f709": 0.0, "f710": 121.0, "f711": 254.0, "f712": 254.0, "f713": 219.0, "f714": 40.0, "f715": 0.0, "f716": 0.0, "f717": 0.0, "f718": 0.0, "f719": 0.0, "f720": 0.0, "f721": 0.0, "f722": 0.0, "f723": 0.0, "f724": 0.0, "f725": 0.0, "f726": 0.0, "f727": 0.0, "f728": 0.0, "f729": 0.0, "f730": 0.0, "f731": 0.0, "f732": 0.0, "f733": 0.0, "f734": 0.0, "f735": 0.0, "f736": 0.0, "f737": 0.0, "f738": 121.0, "f739": 254.0, "f740": 207.0, "f741": 18.0, "f742": 0.0, "f743": 0.0, "f744": 0.0, "f745": 0.0, "f746": 0.0, "f747": 0.0, "f748": 0.0, "f749": 0.0, "f750": 0.0, "f751": 0.0, "f752": 0.0, "f753": 0.0, "f754": 0.0, "f755": 0.0, "f756": 0.0, "f757": 0.0, "f758": 0.0, "f759": 0.0, "f760": 0.0, "f761": 0.0, "f762": 0.0, "f763": 0.0, "f764": 0.0, "f765": 0.0, "f766": 0.0, "f767": 0.0, "f768": 0.0, "f769": 0.0, "f770": 0.0, "f771": 0.0, "f772": 0.0, "f773": 0.0, "f774": 0.0, "f775": 0.0, "f776": 0.0, "f777": 0.0, "f778": 0.0, "f779": 0.0, "f780": 0.0, "f781": 0.0, "f782": 0.0, "f783": 0.0, "Scored Probabilities_0": 1.7306872933250431e-07, "Scored Probabilities_1": 3.3177526751193424e-09, "Scored Probabilities_2": 6.772526557729492e-07, "Scored Probabilities_3": 5.018638683008445e-05, "Scored Probabilities_4": 3.5781842069911e-11, "Scored Probabilities_5": 4.2981825008019914e-08, "Scored Probabilities_6": 6.350046754243676e-14, "Scored Probabilities_7": 0.9999483485221952, "Scored Probabilities_8": 1.3431149602373933e-07, "Scored Probabilities_9": 4.341226706439234e-07, "Scored Labels": 7.0}]}}'
This is the first time I've seen this type of object. How can I get the value of Scored Probabilities_n (n is from 0 to 9) and the Scored Labels? Furthermore, can I get the maximum value (in this case it should be "Scored Probabilities_7": 0.9999483485221952)?
Even when I tried some ways to get the highest value of the variable but it's somehow difficult:
print(max(result))
125
As I can see, there's no 125 value in the variable. So does it mean the normal calculation can not be done on this too? I expected to see the answer on my question above. Thank you!
You can use:
import json
d = json.loads(result.decode('utf-8'))['Results']['WebServiceOutput0'][0]
d['Scored Labels']
# 1.7306872933250431e-07
max_p = max((k for k in d if k.startswith('Scored Probabilities_')), key=d.get)
# 'Scored Probabilities_7'
d[max_p]
# 0.9999483485221952
I have variables as follows:
J = range (1,16)
T = range (1,9)
x= {} # 0,1 decision variable to be determined
These variables turn into combinations of x[j,t].
I am trying to implement a constraint for unacceptable t types in T for x[j,t] combinations that make the x var = 0.
I have a dictionary 'U' with j's as the key and t types and values stored in a list. Zero value means t is unacceptable, 1 is acceptable. The index is range 1-9, not 0-8. So in the example below, j 2, type 3 (bc its at index 3 on range(1,9)) is the only acceptable value.
{1: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
2: [0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
3: [0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
4: [1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
5: [0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
6: [1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
7: [0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
8: [0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
9: [0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
10: [0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
11: [0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
12: [0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
13: [0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
14: [0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
15: [0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0]
}
I am struggling in trying to get the x[j,t] combinations bc of the misaligned index. I set it up like so:
for j,t in x:
if t in U[j]==0:
# do the thing... #addConstr(x[j,t], GRB.EQUAL,0)
So for j 2 the results I need are {(2,1):0, (2,2):0, (2,4):0, (2,5):0, (2,6):0, (2,7):0, (2,8):0} where the index value on range (1,9) becomes the t value in the tupledict.
Any pointers? Thank you!
Assuming your example data is stored in U, what you want to do is:
j_results = []
for j,types in U.items():
results = {}
for t in types:
if t == 0.0:
result[(j,int(t))] = 0
j_results.append(result)
j_results list will contain all results like you described:
for j 2 the results I need are {(2,1):0, (2,2):0, (2,4):0, (2,5):0, (2,6):0, (2,7):0, (2,8):0}
will be in j_result[1] (counter intuitive because your U data start from 1)
Note the int cast, because data you provided has floats, but results you provided are a tuple of ints.
I'm trying to use scikit-learn to do some ML.
I am using the preprocessing module to prep my data. The data are of type float.
From reading other questions regarding this issue: ValueError: setting an array element with a sequence, it's either due to wrong structure of my data or because my data is of type string. Neither seem to be the case here.
Please let me know if you have any idea how to solve this issue or what it even means. Thank you.
The code:
print(X)
pred_X = np.array(pred_X)
pred_Y = np.array(pred_Y)
X = np.array(X)
Y = np.array(Y)
X = preprocessing.scale(X)
pred_X = preprocessing.scale(pred_X)
print(x):
[[547180.0, 120.0, 113.0, 456701.0, 1.0, 6.43, -1.0, 0.313, 0.42, 0.267 3.0, 11800.0, 607208.0, 120.0, 113.0, 456701.0, 1.0, 0.273, 0.331, 0.154, 6.0, 10300.0, 458015.0, 113.0, 120.0, 45328 6.0, 1.0, 2.54, -1.0, 0.32, 0.443, 0.257, 3.0, 92000.0, 543685.0, 120.0, 113.0, 456701.0, 1.0, 6.43, 1.0, 0.296, 0.4, 0.234, 2.0, 8800.0, 594809.0, 475582.0, 120.0, 113.0, 456701.0, 1.0, 1.0, 0.295, 0.384, 0.264, 4.0, 7700.0],
[547180.0, 120.0, 113.0, 456701.0, 1.0, 6.43, -1.0, 0.313, 0.42, 0.267, 3.0, 11800.0, 607208.0, 120.0, 113.0, 456701.0, 1.0, 0.273, 0.331, 0.154, 6.0, 10300.0, 458015.0, 113.0, 120.0, 453286.0, 1.0, 2.54, -1.0, 0.32, 0.443, 0.257, 3.0, 92000.0, 543685.0, 120.0, 113.0, 456701.0, 1.0, 6.43, 1.0, 0.296, 0.4, 0.234, 2.0, 8800.0, 594809.0, 435062.0, 120.0, 113.0, 456701.0, 1.0, 1.0, 0.312, 0.364, 0.154, 5.0, 6900.0],
[547180.0, 120.0, 113.0, 456701.0, 1.0, 6.43, -1.0, 0.313, 0.42, 0.267, 3.0, 11800.0, 607208.0, 120.0, 113.0, 456701.0, 1.0, 0.273, 0.331, 0.154, 6.0, 10300.0, 458015.0, 113.0, 120.0, 453286.0, 1.0, 2.54, -1.0, 0.32, 0.443, 0.257, 3.0, 92000.0, 543685.0, 120.0, 113.0, 456701.0, 1.0, 6.43, 1.0, 0.296, 0.4, 0.234, 2.0, 8800.0, 594809.0, 446308.0, 120.0, 113.0, 456701.0, 1.0, 0.0, 0.221, 0.28e, 0.115, 8.0, 6400.0]]
The Error:
Traceback (most recent call last):
File "sampleSVM.py", line 46, in <module>
X = preprocessing.scale(X)
File "/home/user/.local/lib/python3.5/site-packages/sklearn/preprocessing/data.py", line 133, in scale
dtype=FLOAT_DTYPES)
File "/home/user/.local/lib/python3.5/site-packages/sklearn/utils/validation.py", line 433, in check_array
array = np.array(array, dtype=dtype, order=order, copy=copy)
ValueError: setting an array element with a sequence.
Your input array X is malformed. There are 59 elements in row 1, and 58 in rows 2 & 3. When you convert to a numpy array it becomes an array of shape (3,) with dtype=Object.
The solution is to check and fix your input data. Each row in X must be the same length.