找回密码
 立即注册→加入我们

QQ登录

只需一步,快速开始

搜索
热搜: 下载 VB C 实现 编写
查看: 2471|回复: 0

机器学习&深度学习案例展示

[复制链接]
发表于 2017-10-21 18:25:53 | 显示全部楼层 |阅读模式

欢迎访问技术宅的结界,请注册或者登录吧。

您需要 登录 才可以下载或查看,没有账号?立即注册→加入我们

×
1.情感分析

分析一段话的感情色彩是乐观的,还是消极的

  1. import Algorithmia

  2. def print_sentiment(phrase):
  3.     input = {
  4.       "document": phrase,
  5.       "language":"auto"
  6.     }
  7.     client = Algorithmia.client('simZVCjjKPPXZBthxtGBQ8GyYpY1')
  8.     algo = client.algo('nlp/SentimentAnalysis/1.0.4')
  9.     sentiment = algo.pipe(input).result[0]["sentiment"]
  10.     if sentiment > 0:
  11.         print("positive sentiment")
  12.     else:
  13.         print("negative sentiment")
  14.         
  15. print_sentiment("I really like Algorithmia!")
  16. print_sentiment("I really don't like Algorithmia!")
  17. print_sentiment("Algorithmia'yi cok seviyorum.")
  18. print_sentiment("Je déteste les grenouilles")
复制代码


positive sentiment
negative sentiment
positive sentiment
negative sentiment

也可以获取更详细的信息:
    client = Algorithmia.client('simZVCjjKPPXZBthxtGBQ8GyYpY1')
    algo = client.algo('nlp/SocialSentimentAnalysis/0.1.4')
    print(algo.pipe(input).result)

[{'compound': 0.474, 'negative': 0, 'neutral': 0.393, 'positive': 0.607, 'sentence': 'I really like Algorithmia!'}]
[{'compound': -0.398, 'negative': 0.472, 'neutral': 0.528, 'positive': 0, 'sentence': "I really don't like Algorithmia!"}]


2.语义概括
从一大段文字中进行概括总结


  1. import Algorithmia

  2. input = "In the history of artificial intelligence, an AI winter is a period of reduced funding and interest in artificial intelligence research. The term was coined by analogy to the idea of a nuclear winter. The field has experienced several hype cycles, followed by disappointment and criticism, followed by funding cuts, followed by renewed interest years or decades later. The term first appeared in 1984 as the topic of a public debate at the annual meeting of AAAI (then called the "American Association of Artificial Intelligence"). It is a chain reaction that begins with pessimism in the AI community, followed by pessimism in the press, followed by a severe cutback in funding, followed by the end of serious research. At the meeting, Roger Schank and Marvin Minsky—two leading AI researchers who had survived the "winter" of the 1970s—warned the business community that enthusiasm for AI had spiraled out of control in the '80s and that disappointment would certainly follow. Three years later, the billion-dollar AI industry began to collapse. Hypes are common in many emerging technologies, such as the railway mania or the dot-com bubble. An AI winter is primarily a collapse in the perception of AI by government bureaucrats and venture capitalists. Despite the rise and fall of AI's reputation, it has continued to develop new and successful technologies. AI researcher Rodney Brooks would complain in 2002 that "there's this stupid myth out there that AI has failed, but AI is around you every second of the day." In 2005, Ray Kurzweil agreed: "Many observers still think that the AI winter was the end of the story and that nothing since has come of the AI field. Yet today many thousands of AI applications are deeply embedded in the infrastructure of every industry." He added: "the AI winter is long since over.""
  3. client = Algorithmia.client('simZVCjjKPPXZBthxtGBQ8GyYpY1')
  4. algo = client.algo('nlp/Summarizer/0.1.6')
  5. print(algo.pipe(input).result)
复制代码


In the history of artificial intelligence, an AI winter is a period of reduced funding and interest in artificial intelligence research. The term was coined by analogy to the idea of a nuclear winter. The field has experienced several hype cycles, followed by disappointment and criticism, followed by funding cuts, followed by renewed interest years or decades later.

3.编程语言检测
输入一段代码,分析编程语言类型

  1. import Algorithmia

  2. input = "/* Simple JavaScript example */\n\n// add two numbers\nfunction add(n, m) {\n  return n + m;\n}"
  3. client = Algorithmia.client('simZVCjjKPPXZBthxtGBQ8GyYpY1')
  4. algo = client.algo('PetiteProgrammer/ProgrammingLanguageIdentification/0.1.3')

  5. algo.pipe(input).result
复制代码


[['javascript', 0.9898891716577288],
['markdown', 0.003837364611352919],
['java', 0.0018736157456299355],
['php', 0.001753187646371167],
['c', 0.0009585207454160036],
['lua', 0.0007419186073970403],
['html', 0.00035180268743055217],
['objective-c', 0.00027798425161126557],
['sql', 0.0001728341808434431],
['css', 3.861177400551988e-05],
['c++', 3.439039144376966e-05],
['swift', 3.122888156291083e-05],
['bash', 1.3677125153852449e-05],
['ruby', 1.2247314781813987e-05],
['perl', 5.5816600359435255e-06],
['c#', 3.8442524620865984e-06],
['scala', 3.723956933340268e-06],
['python', 1.5721135605950836e-07],
['r', 6.431838326426007e-08],
['haskell', 4.036764786336714e-08],
['vb', 3.261245241114874e-08]]

4.python语句预测

  1. import Algorithmia

  2. input = {"code": "from __future__ import", "num_results": 5}
  3. client = Algorithmia.client('simZVCjjKPPXZBthxtGBQ8GyYpY1')
  4. algo = client.algo('PetiteProgrammer/pythoncodeprediction/1.0.4')
复制代码


[['absolute_import', 0.4474910795688629],
['unicode_literals', 0.2473190277814865],
['(', 0.197650209069252],
['print_function', 0.0650412067770958],
['division', 0.03176164627075195]]


  1. import Algorithmia

  2. input = {"code": "for i in", "num_results": 5}
  3. client = Algorithmia.client('simZVCjjKPPXZBthxtGBQ8GyYpY1')
  4. algo = client.algo('PetiteProgrammer/pythoncodeprediction/1.0.4')
  5. algo.pipe(input).result
复制代码


[['range', 0.6257643103599548],
['<UNK>', 0.1413002461194992],
['xrange', 0.05714259296655655],
['self', 0.02985670417547226],
['(', 0.022345777601003647]]

以上这写代码都出自算法市场https://algorithmia.com/,在未来,算法也可以像App一样推广
回复

使用道具 举报

本版积分规则

QQ|Archiver|小黑屋|技术宅的结界 ( 滇ICP备16008837号 )|网站地图

GMT+8, 2024-11-22 09:21 , Processed in 0.031878 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表