anaconda安装shapefile_linux + anaconda + tensorflow环境安装

anaconda 支持 python3.5下 tensorflow

pip 是“A tool for installing and managing Python packages.”,也就是说pip是python的软件安装工具。

whl格式本质上是一个压缩包,里面包含了py文件,以及经过编译的pyd文件。使得可以在不具备编译环境的情况下,选择合适自己的python环境进行安装。

安装方法很简单,进入命令行输入pip install xxxx.whl或者如果是升级pip install -U xxxx.whl即可。

Conda 是一个开源的软件包管理系统和环境管理系统,用于安装多个版本的软件包及其依赖关系,并在它们之间轻松切换。

install anaconda

conda install git

添加清华安装镜像

conda config --add channels Tsinghua Open Source Mirror

conda config --set show_channel_urls yes

启用anaconda图形化界面

$ source ~/anaconda3/bin/activate root

$ anaconda-navigator

附件:使用dpkg -L python来查看安装在什么目录

第一个tensorflow程序

# -*- coding: utf-8 -*-

"""

Spyder Editor cjy

This is a 简单的线性回归 script file.

"""

#1.数据准备

#实际的数据大家可以通过pandas等package读入,也可以使用自带的Boston House Price数据集,这里为了简单,我们自己手造一点数据集。

import numpy as np

import tensorflow as tf

import matplotlib.pyplot as plt

plt.rcParams["figure.figsize"] = (14,8)

n_observations = 100

xs = np.linspace(-3, 3, n_observations)

ys = np.sin(xs) + np.random.uniform(-0.5, 0.5, n_observations)

plt.scatter(xs, ys)

#2.准备好placeholder

X = tf.placeholder(tf.float32, name='X')

Y = tf.placeholder(tf.float32, name='Y')

#3.初始化参数/权重

W = tf.Variable(tf.random_normal([1]), name='weight')

b = tf.Variable(tf.random_normal([1]), name='bias')

#4.计算预测结果

Y_pred = tf.add(tf.multiply(X, W), b)

#5.计算损失函数值

loss = tf.square(Y - Y_pred, name='loss')

#6.初始化optimizer

learning_rate = 0.01

optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(loss)

#7.指定迭代次数,并在session里执行graph

n_samples = xs.shape[0]

with tf.Session() as sess:

# 记得初始化所有变量

sess.run(tf.global_variables_initializer())

writer = tf.summary.FileWriter('./graphs/linear_reg', sess.graph)

# 训练模型

for i in range(50):

total_loss = 0

for x, y in zip(xs, ys):

# 通过feed_dic把数据灌进去

_, l = sess.run([optimizer, loss], feed_dict={X: x, Y:y})

total_loss += l

if i%5 ==0:

print('Epoch {0}: {1}'.format(i, total_loss/n_samples))

# 关闭writer

writer.close()

# 取出w和b的值

W, b = sess.run([W, b])

print(W,b)

print("W:"+str(W[0]))

print("b:"+str(b[0]))

plt.plot(xs, ys, 'bo', label='Real data')

plt.plot(xs, xs * W + b, 'r', label='Predicted data')

plt.legend()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值