简体   繁体   中英

Machine Learning in Python - How can I tell if an input is a number or not

I would like to know if a given input is a number or not a number. For example, if entered '1', then it is a number, 'one', 'three hundred' would also be numbers, but 'cat' would obviously not be a number. Furthermore, I would like for it to recognize that "three hundred" is actually the integer 300.

I figured that machine learning classification would be the best way to do something like this (correct me if I'm wrong), but have no idea how to get started. If someone can point to some steps to take to solve this problem, it would be appreciated.

I don't think ML is necessary nor best for what you want to achieve on your project. I say this because it can be done with a single function while ML would require huge data sets for it to actually learn something.

number words to integers then return eval

//pseudo code
function ( input )
  if input is a number word
    print its a number
    print the number
  else
    print its not a number

To check and convert number words to integers, here are some suggestions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM