Skip to content

Commit

Permalink
fix(4.2): 代码块
Browse files Browse the repository at this point in the history
 fix(4.2): 代码块
  • Loading branch information
camera-2018 authored Apr 19, 2023
2 parents 3a1f009 + 6bf9d29 commit 1a3fdf2
Showing 1 changed file with 31 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,23 @@

```python
def estimate_house_sales_price(num_of_bedrooms, sqft, neighborhood):
price = 0 # In my area, the average house costs $200 per sqft
price_per_sqft = 200 if neighborhood == "hipsterton":
price = 0 # In my area, the average house costs $200 per sqft
price_per_sqft = 200
if neighborhood == "hipsterton":
# but some areas cost a bit more
price_per_sqft = 400 elif neighborhood == "skid row":
price_per_sqft = 400
elif neighborhood == "skid row":
# and some areas cost less
price_per_sqft = 100 # start with a base price estimate based on how big the place is
price = price_per_sqft * sqft # now adjust our estimate based on the number of bedrooms
if num_of_bedrooms == 0:
# Studio apartments are cheap
price = price — 20000
else:
price_per_sqft = 100 # start with a base price estimate based on how big the place is
price = price_per_sqft * sqft # now adjust our estimate based on the number of bedrooms
if num_of_bedrooms == 0:
# Studio apartments are cheap
price = price - 20000
else:
# places with more bedrooms are usually
# more valuable
price = price + (num_of_bedrooms * 1000) return price
price = price + (num_of_bedrooms * 1000)
return price
```

假如你像这样瞎忙几个小时,最后也许会得到一些像模像样的东西。但是永远感觉差点东西。
Expand All @@ -110,7 +113,8 @@ def estimate_house_sales_price(num_of_bedrooms, sqft, neighborhood):

```python
def estimate_house_sales_price(num_of_bedrooms, sqft, neighborhood):
price = <电脑电脑快显灵> return price
price = <电脑电脑快显灵>
return price
```

如果你可以找到这么一个公式:
Expand All @@ -125,11 +129,12 @@ Y(房价)=W(参数)*X1(卧室数量)+W*X2(面积)+W*X3(地段)

```python
def estimate_house_sales_price(num_of_bedrooms, sqft, neighborhood):
price = 0 # a little pinch of this
price += num_of_bedrooms *<strong> 1.0</strong> # and a big pinch of that
price += sqft * <strong>1.0</strong> # maybe a handful of this
price += neighborhood * <strong>1.0</strong> # and finally, just a little extra salt for good measure
price += <strong>1.0</strong> return price
price = 0 # a little pinch of this
price += num_of_bedrooms *1.0 # and a big pinch of that
price += sqft * 1.0 # maybe a handful of this
price += neighborhood * 1.0 # and finally, just a little extra salt for good measure
price += 1.0
return price
```

第二步把每个数值都带入进行运算。
Expand Down Expand Up @@ -211,11 +216,11 @@ def estimate_house_sales_price(num_of_bedrooms, sqft, neighborhood):

```python
def estimate_house_sales_price(num_of_bedrooms, sqft, neighborhood):
price = 0# a little pinch of this
price += num_of_bedrooms * 0.123# and a big pinch of that
price += sqft * 0.41# maybe a handful of this
price += neighborhood * 0.57
return price
price = 0# a little pinch of this
price += num_of_bedrooms * 0.123# and a big pinch of that
price += sqft * 0.41# maybe a handful of this
price += neighborhood * 0.57
return price
```

我们换一个好看的形式给他展示
Expand Down Expand Up @@ -329,9 +334,11 @@ print('y_pred=',y_test.data)

```python
model = Sequential([Dense(32, input_shape=(784,)),
Activation('relu'),Dense(10),Activation('softmax')])# 你也可以通过 .add() 方法简单地添加层: model = Sequential()
model.add(Dense(32, input_dim=784))
model.add(Activation('relu'))# 激活函数,你可以理解为加上这个东西可以让他效果更好
Activation('relu'),Dense(10),Activation('softmax')])
# 你也可以通过 .add() 方法简单地添加层:
model = Sequential()
model.add(Dense(32, input_dim=784))
model.add(Activation('relu'))# 激活函数,你可以理解为加上这个东西可以让他效果更好
```

虽然我们的神经网络要比上次大得多(这次有 324 个输入,上次只有 3 个!),但是现在的计算机一眨眼的功夫就能够对这几百个节点进行运算。当然,你的手机也可以做到。
Expand Down

0 comments on commit 1a3fdf2

Please sign in to comment.