M
M
Mykola Kulik2020-06-12 21:27:58
Python
Mykola Kulik, 2020-06-12 21:27:58

What is this obscure bug in Discord Bot?

Hello everyone. The bottom line is that I'm developing a bot in Discord. Here is his code:

import discord
from discord.ext import commands
from math import *
from sklearn.tree import DecisionTreeClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
import random as rn
import numpy as np

client = commands.Bot (command_prefix="'")

@client.event
async def on_ready():
    print("hi")

@client.command(pass_context=True)
async def hello(ctx):
    author = ctx.message.author
    await ctx.send(f"{author.mention} Hello!")

@client.command(pass_context=True)
async def hi(ctx):
    author = ctx.message.author
    await ctx.send(f"{author.mention} Hello!")

@client.command(pass_context=True)
async def smile(ctx):
    author = ctx.message.author
    smiles_massive = [":)", ";)", "%)", "=)", ":}", ";}", "%}", "=}", ":]", ";]", "%]", "=]", ":D", ";D", "%D", "=D"]
    smile_index = rn.randint(0, len(smiles_massive)-1)
    smile = smiles_massive[smile_index]
    await ctx.send(f"{author.mention} " + smile)

@client.command(pass_context=True)
async def math(ctx, arg):
    author = ctx.message.author
    pi = 3.1415926535897932384626433  
    e = 2.7182818284590452353602874
    if (arg == "euler"):
        await ctx.send(f"""{author.mention} ```
           (тут пасхалка для математиков, да)```""")
    else:
        result = eval(arg)
        await ctx.send(f"{author.mention} Result: " + str(result))

@client.command(pass_context=True)
async def machlearn(ctx, feature_data, target_data, new_data):
    X = np.array(feature_data).reshape(-1,1)
    y = np.array(target_data).reshape(-1,1)
    classify_method = rn.randint(0, 1)
    if classify_method == 0:
        clf = DecisionTreeClassifier()
    if classify_method == 1:
        clf = KNeighborsClassifier()
    clf.fit(X, y)
    pred = clf.predict(np.array(new_data).reshape(-1,1))
    metr = accuracy_score(y, pred)
    await ctx.send(f"{author.mention} Result: " + str(metr))

client.run("токен")


The machlearn team is under development. With him full tin. What I just have not tried, everything goes down the drain.
When entering the command:
'machlearn "" "[0, 0, 1, 1]" ""

I'm getting an error:
Ignoring exception in command machlearn:
Traceback (most recent call last):
File "C:\Users\Nik\AppData\Local\Programs\Python\Python38-32\lib\site-packages
\discord\ext\commands\core.py ", line 83, in wrapped
ret = await coro(*args, **kwargs)
File "main.py", line 57, in machlearn
clf.fit(X, y)
File "C:\Users\Nik\AppData\ Local\Programs\Python\Python38-32\lib\site-packages
\sklearn\tree\_classes.py", line 890, in fit
super().fit(
File "C:\Users\Nik\AppData\Local\Programs \Python\Python38-32\lib\site-packages
\sklearn\tree\_classes.py", line 156, in fit
X, y = self._validate_data(X, y,
File "C:\Users\Nik\AppData\Local\Programs\Python\Python38-32\lib\site-packages
\sklearn\base.py", line 429, in _validate_data
X = check_array(X, **check_X_params)
File "C:\Users\Nik\AppData\Local\Programs\Python\Python38-32\lib\site-packages
\sklearn\utils\validation.py", line 73, in inner_f
return f(**kwargs)
File "C :\Users\Nik\AppData\Local\Programs\Python\Python38-32\lib\site-packages
\sklearn\utils\validation.py", line 599, in check_array
array = np.asarray(array, order=order, dtype=dtype)
File "C:\Users\Nik\AppData\Local\Programs\Python\Python38-32\lib\site-packages
\numpy\core\_asarray.py", line 85, in asarray
return array(a, dtype, copy=False,order=order)
ValueError: could not convert string to float: ''

The above exception was the direct cause of the following exception:

Traceback ( most recent call last):
File "C:\Users\Nik\AppData\Local\Programs\Python\Python38-32\lib\site-packages
\discord\ext\commands\bot.py", line 892, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\Nik\AppData\Local\Programs\Python\Python38-32\lib\site-packages
\discord\ext\commands\core.py", line 797, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\Nik\AppData\Local\Programs\Python\Python38-32\lib\site-packages
\discord\ext\commands\core. py", line 92, wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception:
ValueError: could not convert string to float: ''


Question: what's the matter? How can this be fixed? And what does it look like in code?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
soremix, 2020-06-12
@PythonistGit

Not an expert but

  1. You pass the string '' to np.array() . In X and y you need to pass a list
  2. Further, an error will occur related to the different size of the matrix, because X - 8, y - 4

U
Uno, 2020-06-12
@Noizefan


could not convert string to float : ''

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question