楼主: ReneeBK
1377 16

[Microsoft Cognitive Toolkit]Logistic Regression using CNTK [推广有奖]

  • 1关注
  • 62粉丝

VIP

学术权威

14%

还不是VIP/贵宾

-

TA的文库  其他...

R资源总汇

Panel Data Analysis

Experimental Design

威望
1
论坛币
49517 个
通用积分
53.5804
学术水平
370 点
热心指数
273 点
信用等级
335 点
经验
57815 点
帖子
4006
精华
21
在线时间
582 小时
注册时间
2005-5-8
最后登录
2023-11-26

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
This tutorial is targeted to individuals who are new to CNTK and to machine learning. In this tutorial, you will train a simple yet powerful machine learning model that is widely used in industry for a variety of applications. The model trained below scales to massive data sets in the most expeditious manner by harnessing computational scalability leveraging the computational resources you may have (one or more CPU cores, one or more GPUs, a cluster of CPUs or a cluster of GPUs), transparently via the CNTK library.
The following notebook uses Python APIs. If you are looking for this example in BrainScript, please look here.
IntroductionProblem: A cancer hospital has provided data and wants us to determine if a patient has a fatal malignant cancer vs. a benign growth. This is known as a classification problem. To help classify each patient, we are given their age and the size of the tumor. Intuitively, one can imagine that younger patients and/or patients with small tumors are less likely to have a malignant cancer. The data set simulates this application: each observation is a patient represented as a dot (in the plot below), where red indicates malignant and blue indicates benign. Note: This is a toy example for learning; in real life many features from different tests/examination sources and the expertise of doctors would play into the diagnosis/treatment decision for a patient.

本帖隐藏的内容

Logistic Regression using Microsoft Cognitive Toolkit.pdf (111.47 KB)




二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:regression Microsoft Cognitive regressio logistic

沙发
ReneeBK 发表于 2017-9-17 02:08:09 |只看作者 |坛友微信交流群
  1. # Figure 3
  2. Image(url= "https://www.cntk.ai/jup/logistic_neuron.jpg", width=300, height=200)
复制代码

使用道具

藤椅
ReneeBK 发表于 2017-9-17 02:08:33 |只看作者 |坛友微信交流群
  1. # Import the relevant components
  2. from __future__ import print_function
  3. import numpy as np
  4. import sys
  5. import os

  6. import cntk as C
  7. import cntk.tests.test_utils
  8. cntk.tests.test_utils.set_device_from_pytest_env() # (only needed for our build system)
  9. C.cntk_py.set_fixed_random_seed(1) # fix the random seed so that LR examples are repeatable
复制代码

使用道具

板凳
ReneeBK 发表于 2017-9-17 02:09:16 |只看作者 |坛友微信交流群
  1. # Ensure that we always get the same results
  2. np.random.seed(0)

  3. # Helper function to generate a random data sample
  4. def generate_random_data_sample(sample_size, feature_dim, num_classes):
  5.     # Create synthetic data using NumPy.
  6.     Y = np.random.randint(size=(sample_size, 1), low=0, high=num_classes)

  7.     # Make sure that the data is separable
  8.     X = (np.random.randn(sample_size, feature_dim)+3) * (Y+1)
  9.    
  10.     # Specify the data type to match the input variable used later in the tutorial
  11.     # (default type is double)
  12.     X = X.astype(np.float32)   
  13.    
  14.     # convert class 0 into the vector "1 0 0",
  15.     # class 1 into the vector "0 1 0", ...
  16.     class_ind = [Y==class_number for class_number in range(num_classes)]
  17.     Y = np.asarray(np.hstack(class_ind), dtype=np.float32)
  18.     return X, Y
复制代码

使用道具

报纸
ReneeBK 发表于 2017-9-17 02:10:00 |只看作者 |坛友微信交流群
  1. # Create the input variables denoting the features and the label data. Note: the input
  2. # does not need additional info on the number of observations (Samples) since CNTK creates only
  3. # the network topology first
  4. mysamplesize = 32
  5. features, labels = generate_random_data_sample(mysamplesize, input_dim, num_output_classes)
复制代码

使用道具

地板
auirzxp 学生认证  发表于 2017-9-17 02:10:11 |只看作者 |坛友微信交流群

使用道具

7
ReneeBK 发表于 2017-9-17 02:11:59 |只看作者 |坛友微信交流群
  1. # Plot the data
  2. import matplotlib.pyplot as plt
  3. %matplotlib inline

  4. # let 0 represent malignant/red and 1 represent benign/blue
  5. colors = ['r' if label == 0 else 'b' for label in labels[:,0]]

  6. plt.scatter(features[:,0], features[:,1], c=colors)
  7. plt.xlabel("Age (scaled)")
  8. plt.ylabel("Tumor size (in cm)")
  9. plt.show()
复制代码

使用道具

8
ReneeBK 发表于 2017-9-17 02:12:38 |只看作者 |坛友微信交流群
  1. # Figure 4
  2. Image(url= "https://www.cntk.ai/jup/logistic_neuron2.jpg", width=300, height=200)
复制代码

使用道具

9
ReneeBK 发表于 2017-9-17 02:13:07 |只看作者 |坛友微信交流群
  1. # Define a dictionary to store the model parameters
  2. mydict = {}

  3. def linear_layer(input_var, output_dim):
  4.    
  5.     input_dim = input_var.shape[0]
  6.     weight_param = C.parameter(shape=(input_dim, output_dim))
  7.     bias_param = C.parameter(shape=(output_dim))
  8.    
  9.     mydict['w'], mydict['b'] = weight_param, bias_param

  10.     return C.times(input_var, weight_param) + bias_param
复制代码

使用道具

10
ReneeBK 发表于 2017-9-17 02:15:46 |只看作者 |坛友微信交流群
  1. Training
  2. The output of the softmax is the probabilities of an observation belonging each of the respective classes. For training the classifier, we need to determine what behavior the model needs to mimic. In other words, we want the generated probabilities to be as close as possible to the observed labels. We can accomplish this by minimizing the difference between our output and the ground-truth labels. This difference is calculated by the cost or loss function.

  3. In [14]:
  4. label = C.input_variable(num_output_classes, np.float32)
  5. loss = C.cross_entropy_with_softmax(z, label)
复制代码

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-11-5 20:46