提交 48daaab1 编写于 作者: W wizardforcel

2021-02-21 12:12:39

上级 b93dec0b
......@@ -25,7 +25,7 @@ Scala 还提供了一种非常简洁的语法,可以将其转换为更少的
因此,对于像我这样开始涉足数据科学的开发人员来说,Scala 似乎是一个更自然的选择,但是,扰流警报却使我们最终专注于 Python。 这种选择有多种原因:
* Python 作为一种语言,本身也有很多发展。 它是一种动态编程语言,具有与 Scala 相似的优点,例如函数式编程,简洁的语法等。
* Python has seen, over the last few years, a meteoric rise among data scientists, overtaking longtime rival R as the overall preferred language for data science, as demonstrated by a quick search for the terms `Python Data Science`, `Python Machine Learning`, `R Data Science`, and `R Machine Learning` on Google Trends:
* 在过去的几年中,Python见证了数据科学家的飞速发展,已取代长期的竞争对手R作为数据科学的整体首选语言,这可以通过在Google趋势中快速搜索术语“Python数据科学”,“Python机器学习”,“R 数据科学”和“R 机器学习”来证明:
![Why choose Python?](img/00011.jpeg)
......@@ -140,7 +140,7 @@ c.NotebookApp.open_browser = False
下一步是使用`pip`工具安装 PixieDust 库:
1. From the Notebook itself, enter the following command in a cell:
1. 从笔记本计算机本身,在单元格中输入以下命令:
```py
!pip install pixiedust
......@@ -478,7 +478,7 @@ display(cars)
* 有一个过滤器切换按钮,使用户可以通过过滤数据来优化他们的探索。 我们将在*过滤*部分中讨论过滤器功能。
* 有一个 Expand / Collapse Pixiedust Output 按钮,用于折叠/扩展输出内容。
* 有一个**选项**按钮可调用一个对话框,该对话框具有特定于当前可视化的配置。
* There's a **Share** button that lets you publish the visualization on the web.
* 有一个“共享”按钮,可让您在网络上发布可视化内容。
### 注意
......@@ -599,7 +599,7 @@ Mapbox 图表的“选项”对话框
为了更好地浏览数据,PixieDust 还提供了一个内置的简单图形界面,可让您快速过滤正在可视化的数据。 您可以通过单击顶层菜单中的过滤器切换按钮来快速调用过滤器。 为简单起见,过滤器仅支持仅基于一列构建谓词,这在大多数情况下足以验证简单假设(基于反馈,将来可能会增强此功能以支持多个谓词)。 过滤器用户界面会自动让您选择要过滤的列,并根据其类型显示不同的选项:
* **Numerical type**: The user can select a mathematical comparator and enter a value for the operand. For convenience, the UI will also show statistical values related to the chosen column, which can be used when picking the operand value:
* **数值类型**:用户可以选择一个数学比较器并为操作数输入一个值。 为了方便起见,UI还将显示与所选列相关的统计值,这些统计值可在选择操作数值时使用:
![Filtering](img/00040.jpeg)
......@@ -730,7 +730,7 @@ PixieDust 使用 PixieGateway 组件提供了该解决方案的实现。 PixieGa
PixieGateway 架构图
1. The PixieApp is published into the PixieGateway server directly from the Notebook and a URL is generated. Behind the scene, PixieGateway allocates a Jupyter Kernel to run the PixieApp. Based on configuration, the PixieApp could share the kernel instance with other apps or have a dedicated kernel based on needs. The PixieGateway middleware can scale horizontally by managing the lifecycle of multiple kernels instances, which themselves can either be local to the server or remote on a cluster.
1. PixieApp直接从Notebook中发布到PixieGateway服务器中,并生成一个URL。 在后台,PixieGateway分配了一个Jupyter内核来运行PixieApp。 根据配置,PixieApp可以与其他应用程序共享内核实例,也可以根据需要拥有专用的内核。 PixieGateway中间件可以通过管理多个内核实例的生命周期来水平扩展,这些实例本身可以是服务器本地的,也可以是群集上的远程的。
### 注意
......
......@@ -65,7 +65,7 @@ app.run()
路由用于动态更新全部或部分客户端屏幕。 可以根据以下规则在任何类方法上使用`@route`装饰器轻松定义它们:
* A route method is required to return a string that represents the HTML fragment for the update.
* 需要一个路由方法来返回一个字符串,该字符串表示更新的HTML片段。
### 注意
......@@ -123,13 +123,13 @@ app.run()
了解变量和方法如何进入路由返回的 JinJa2 模板字符串的范围也很重要。 PixieApp 自动提供对三种类型的变量和方法的访问:
* **Class variables and methods** : These are accessible using the `this` keyword.
* **类变量和方法**:可以使用`this`关键字进行访问。
### 注意
**注意**:我们之所以不使用更具 Pythonic 风格的`self`关键字,是因为 Jinja2 本身已经采用了该关键字。
* **Method arguments**: This is useful when the route arguments use the `*` value and you want to have access to that value at runtime. In this case, you can add arguments to the method itself using the same name as the one defined in the route arguments and the PixieApp framework will automatically pass the correct value.
* **方法参数**:当路由参数使用`*`值并且您希望在运行时可以访问该值时,此方法很有用。 在这种情况下,您可以使用与路由参数中定义的名称相同的名称向方法本身添加参数,并且PixieApp框架将自动传递正确的值。
### 注意
......@@ -1038,7 +1038,7 @@ pd_script="self.show_stats='$val(show_stats{{prefix}})'=='true'">
PixieApp 编程模型提供了一种机制,用于将 HTML 和复杂 UI 构造的逻辑打包到一个小部件中,可以轻松地从其他 PixieApps 中调用该小部件。 创建窗口小部件的步骤如下:
1. 创建一个将包含小部件的 PixieApp 类。
2. Create a route with a special `widget` attribute, as in the example:
2. C创建一个带有特殊`widget`属性的路线,如示例所示:
```py
@route(widget="my_widget")
......
......@@ -116,13 +116,13 @@ Pixiedust version 1.1.10
以下说明将使用 IBM Cloud Kubernetes 服务,但它们可以轻松地适用于其他提供商:
1. Create an IBM Cloud account if you don't already have one and create a container service instance from the catalog.
1. C如果您还没有一个IBM Cloud帐户,请创建一个IBM Cloud帐户并从目录中创建一个容器服务实例。
### 注意
**注意**:精简版计划可免费进行测试。
2. Download and install the Kubernetes CLI ( [https://kubernetes.io/docs/tasks/tools/install-kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl) ) and the IBM Cloud CLI ( [https://console.bluemix.net/docs/cli/reference/bluemix_cli/get_started.html#getting-started](https://console.bluemix.net/docs/cli/reference/bluemix_cli/get_started.html#getting-started) ).
2. 下载并安装 [Kubernetes CLI](https://kubernetes.io/docs/tasks/tools/install-kubectl)[IBM Cloud CLI](https://console.bluemix.net/docs/cli/reference/bluemix_cli/get_started.html#getting-started)
### 注意
......@@ -146,7 +146,7 @@ Pixiedust version 1.1.10
```
5. Download the cluster configuration that will be used by the `kubectl` command, which is executed on your local machine, later on:
5. 下载将由`kubectl`命令使用的集群配置,该命令将在本地计算机上执行,稍后:
```py
bx cs cluster-config my-cluster
......@@ -236,7 +236,7 @@ jupyter kernelgateway --generate-config
* **Python**:`PixieGatewayApp.admin_user_id`,`PixieGatewayApp.admin_password`
* **环境**:`ADMIN_USERID`和`ADMIN_PASSWORD`
* **Storage connector**: Configure a persistent storage for various resources, such as charts, and Notebooks. By default, PixieGateway uses the local filesystem; for example, it will store the published Notebooks under the `~/pixiedust/gateway` directory. Using the local filesystem is probably fine for a local test environment, but when using a Kubernetes install, you will need to explicitly use persistent volumes ([https://kubernetes.io/docs/concepts/storage/persistent-volumes](https://kubernetes.io/docs/concepts/storage/persistent-volumes)), which can be difficult to use. If no persistence strategy is put in place, the persisted files will be deleted when the container is restarted and all your published chart and PixieApps will disappear. PixieGateway provides another option, which is to configure a storage connector that lets you persist the data using the mechanism and backend of your choice.
* **存储连接器**:为各种资源(例如图表和笔记本)配置永久存储。 默认情况下,PixieGateway使用本地文件系统。 例如,它将发布的笔记本存储在`~/pixiedust/gateway`目录下。 对于本地测试环境,使用本地文件系统可能很好,但是在使用Kubernetes安装时,您将需要[显式使用持久卷](https://kubernetes.io/docs/concepts/storage/persistent-volumes),它可能很难使用。 如果没有采用持久性策略,则在重新启动容器时,将删除持久文件,并且所有已发布的图表和PixieApps都将消失。 PixieGateway提供了另一个选项,它是配置一个存储连接器,使您可以使用所选的机制和后端持久化数据。
要为图表配置存储连接器,必须在以下任一配置变量中指定标准类名:
......@@ -253,7 +253,7 @@ jupyter kernelgateway --generate-config
* `CloudantConfig.username / PG_CLOUDANT_USERNAME`
* `CloudantConfig.password / PG_CLOUDANT_PASSWORD`
* **Remote Kernels**: Specify the configuration for a remote Jupyter Kernel Gateway.
* **远程内核**:指定远程Jupyter内核网关的配置。
目前,仅在 Python 模式下支持此配置选项。 您需要使用的变量名称是`ManagedClientPool.remote_gateway_config`。 期望值是一个包含服务器信息的 JSON 对象,可以通过两种方式指定:
......@@ -372,7 +372,7 @@ PixieGateway 架构图
在服务器上部署 PixieApp 时,将分析 Jupyter Notebook 每个单元中包含的代码并将其分为两个部分:
* **预热代码**:这是在主要 PixieApp 定义上方的所有单元格中定义的所有代码。 第一次在内核上启动 PixieApp 应用程序时,此代码仅运行一次,直到重新启动内核或从运行代码中显式调用它之前,该代码才再次运行。 这很重要,因为它将帮助您更好地优化性能。 例如,您应该始终将代码放置在“预热”部分中,该代码将加载大量数据,这些数据不会发生太大变化或可能需要很长时间进行初始化。
* **Run code**: This is code that will be run in its own instance for every user session. The run code is typically extracted from the cell that contains the PixieApp class declaration. The publisher automatically discovers this cell by doing a static analysis of the Python code and specifically looking for the following two criteria, which must both be met:
* **运行代码**:这是将在每个用户会话的自己实例中运行的代码。 运行代码通常是从包含PixieApp类声明的单元格中提取的。 发布者通过对Python代码进行静态分析并专门寻找以下两个条件来自动发现此单元:必须同时满足以下两个条件:
* 该单元格包含一个带有`@PixieApp`批注的类
* 该单元实例化该类并调用其`run()`方法
......@@ -452,10 +452,10 @@ app.run()
* **PixieGateway 服务器**:例如,`http://localhost:8899`
* **页面标题**:简短说明 在浏览器中显示时将用作页面标题的页面
* **Security** : Configure the PixieApp security when accessed through the web:
* **安全**:通过网络访问时配置PixieApp的安全性:
* **No security**
* **Token** : A security token must be added as a query parameter to the URL, for example, `http://localhost:8899/GitHubTracking?token=941b3990d5c0464586d67e48705b9deb` .
* **没有安全**
* **令牌**:必须将安全令牌作为查询参数添加到URL,例如,`http://localhost:8899/GitHubTracking?token=941b3990d5c0464586d67e48705b9deb`
### 注意
......@@ -485,7 +485,7 @@ PixieApp 发布对话框
现在您已经知道如何发布 PixieApp,下面让我们回顾一些开发人员最佳实践和规则,这些经验和规则将帮助您优化打算作为 Web 应用程序发布的 PixieApp:
* 为每个用户会话创建一个 PixieApp 实例,因此,为了提高性能,请确保它不包含长时间运行的代码或不加载大量静态数据(不经常更改的数据)的代码。 而是将其放在“预热代码”部分中,并根据需要从 PixieApp 进行引用。
* Don't forget to add the code that runs the PixieApp in the same cell. If not, you'll end up with a blank page when running it on the web. As a good practice, it is recommended to assign the PixieApp instance into its own variable. For example, do this:
* 不要忘记在同一单元格中添加运行PixieApp的代码。 否则,在网络上运行时将得到空白页。 作为一种好的做法,建议将PixieApp实例分配到其自己的变量中。 例如,执行以下操作:
```py
app = GitHubTracking()
......@@ -652,7 +652,7 @@ PixieDust Chart 选项
管理控制台的用户界面由专注于特定任务的多个菜单组成。 让我们一一看一下:
* **PixieApps**:
* `PixieApps`:
* 有关所有已部署的 PixieApps 的信息:URL,描述等
* 安全管理
......@@ -662,7 +662,7 @@ PixieDust Chart 选项
管理控制台 PixieApp 管理页面
* **Charts**:
* **图表**:
* 有关所有已发布图表的信息:链接,预览等
* 对于示例的操作,删除,下载和嵌入片段
......@@ -671,7 +671,7 @@ PixieDust Chart 选项
管理控制台图表管理页面
* **Kernel Stats**:
* **内核统计**:
以下屏幕截图显示了**内核统计**屏幕:
......@@ -687,7 +687,7 @@ PixieDust Chart 选项
* **正在运行的应用程序**:这是正在运行的 PixieApps 的列表。 每个 PixieApp 是一个向下钻取链接,该链接显示预热代码并运行 PixieApp 的代码。 这对于解决错误非常有用,因为您可以看到 PixieGateway 正在运行什么代码。
* **用户计数**:这是此内核中具有打开会话的用户数。
* **Server Logs**:
* **服务器日志**:
完全访问龙卷风服务器日志以进行故障排除
......
......@@ -203,7 +203,7 @@ app.run()
每种方法都有优点和缺点:
* `pd_widget`技术被实现为路由,并且肯定比`pd_app,`轻巧,后者需要创建一个全新的 PixieApp 实例。 请注意,`pd_widget``pd_app`(通过`parent_pixieapp`变量)都可以访问主机应用程序中包含的所有变量。
* The `pd_app` attribute provides a cleaner separation between the components and more flexibility than widgets. You could, for example, have a button that dynamically invokes multiple PixieApps based on some user selection.
* `pd_app`属性提供了组件之间更清晰的分隔,并且比小部件具有更大的灵活性。 例如,您可以具有一个按钮,该按钮可以根据某些用户选择动态调用多个PixieApp。
### 注意
......@@ -451,7 +451,7 @@ MessageHubStreamingApp().run(
如果您想了解有关 PixieDust 流的更多信息,可以在这里找到其他流应用示例:
* A simple PixieApp that demonstrate how to create streaming visualizations from randomly generated data: [https://github.com/pixiedust/pixiedust/blob/master/notebook/pixieapp-streaming/PixieApp%20Streaming-Random.ipynb](https://github.com/pixiedust/pixiedust/blob/master/notebook/pixieapp-streaming/PixieApp%20Streaming-Random.ipynb)
* [一个简单的PixieApp,演示了如何根据随机生成的数据创建流式可视化](https://github.com/pixiedust/pixiedust/blob/master/notebook/pixieapp-streaming/PixieApp%20Streaming-Random.ipynb)
* [展示如何构建股票行情实时显示的 PixieApp](https://github.com/pixiedust/pixiedust/blob/master/notebook/pixieapp-streaming/PixieApp%20Streaming-Stock%20Ticker.ipynb)
......@@ -468,7 +468,7 @@ PixieApp 框架支持使用浏览器中可用的发布-订阅模式在不同组
发布者可以通过两种方式触发事件:
* **Declarative**: Use the `pd_event_payload` attribute to specify the payload content. This attribute follows the same rules as `pd_options`:
* **声明性**:使用`pd_event_payload`属性指定有效内容。 该属性遵循与`pd_options`相同的规则:
* 每个键/值对必须使用`key=value`表示法进行编码
* 该事件将由点击或更改事件触发
......@@ -501,7 +501,7 @@ PixieApp 框架支持使用浏览器中可用的发布-订阅模式在不同组
[您可以在此处找到代码文件](https://github.com/DTAIEB/Thoughtful-Data-Science/blob/master/chapter%205/sampleCode11.html)。
* **Programmatic**: In some cases, you may want to directly trigger an event via JavaScript. In this case, you can use the `sendEvent(payload, divId)` method of the `pixiedust` global object. The `divId` is an optional argument that specifies the origin of the event. If the `divId` argument is omitted, then it defaults to the `divId` of the element that is currently sending the event. As a result, you should always use `pixiedust.sendEvent` without a `divId` from a JavaScript handler of a user event such as click, and hover.
* **程序化**:在某些情况下,您可能希望通过JavaScript直接触发事件。 在这种情况下,您可以使用`pixiedust`全局对象的`sendEvent(payload, divId)`方法。 `divId`是一个可选参数,用于指定事件的来源。 如果省略了·参数,则默认为当前发送事件的元素的divId。 因此,您应始终使用来自用户事件(例如,点击和悬停)的JavaScript处理程序的`pixiedust.sendEvent`,而不使用`divId`
例子:
......@@ -718,7 +718,7 @@ PixieDust 随附了一些内置渲染器,例如 Matplotlib,Seaborn,Bokeh
添加新的渲染器类似于添加显示可视化(使用相同的 API),尽管实际上更简单,因为您只需要构建一个类(无需构建元数据类)即可。 这是您需要遵循的步骤:
1. 创建一个从专门的`BaseChartDisplay class`继承的 Display 类。 实现所需的`doRenderChart()`方法。
2. Use the `@PixiedustRenderer` decorator to register the `rendererId` (which must be unique across all renderers) and the type of chart being rendered.
2. 使用`@PixiedustRenderer`装饰器注册`rendererId`(在所有渲染器中必须唯一)和要渲染的图表类型。
请注意,相同的`rendererId`可以用于渲染器中包含的所有图表。 PixieDust 提供了一组核心图表类型:
......@@ -811,7 +811,7 @@ class SimpleDisplayWithRenderer(BaseChartDisplay):
pdb.run("<insert a valid python statement here>")
```
* By setting an explicit breakpoint in the code with the `set_trace()` method:
* 通过使用`set_trace()`方法在代码中设置一个明确的断点:
```py
import pdb
......@@ -838,7 +838,7 @@ class SimpleDisplayWithRenderer(BaseChartDisplay):
魔术命令有两种类型:
* **Line magics**: The syntax is `%<magic_command_name> [optional arguments]`for example, `%matplotlib inline`, which configures Matplotlib to output the charts inline in the Notebook output cell.
* **行魔术**:语法为`%<magic_command_name> [optional arguments]`,例如`%matplotlib inline`,它将Matplotlib配置为在Notebook输出单元格中内联输出图表。
它们可以在单元代码中的任何位置调用,甚至可以返回可以分配给 Python 变量的值,例如:
......@@ -853,7 +853,7 @@ class SimpleDisplayWithRenderer(BaseChartDisplay):
[您可以在此处找到所有线魔术的列表](http://ipython.readthedocs.io/en/stable/interactive/magics.html#line-magics)。
* **Cell magics**: The syntax is `%%<magic_command_name> [optional arguments]`. For example, we call the HTML cell magic to display HTML on the output cell:
* **单元魔术**:语法为`%%<magic_command_name> [optional arguments]`。 例如,我们称HTML单元魔术为在输出单元上显示HTML:
```py
%%html
......
......@@ -1204,7 +1204,7 @@ with open(os.path.join(image_dir, "retrained_label.txt"), "w") as f_label:
**注意**:如前所述,该代码相当广泛,并且省略了一部分; 这里仅说明重要部分。 请不要尝试按原样运行以下代码,并且请参阅完整的 Notebook 以获取完整的实现。
1. Decode the `.jpeg` file using the following code:
1. 使用以下代码对`.jpeg`文件进行解码:
```py
def add_jpeg_decoding(model):
......@@ -1241,7 +1241,7 @@ with open(os.path.join(image_dir, "retrained_label.txt"), "w") as f_label:
[您可以在此处找到代码文件](https://github.com/DTAIEB/Thoughtful-Data-Science/blob/master/chapter%206/sampleCode26.py)。
2. Create the bottleneck values (caching them as appropriate) that normalize the image by resizing and rescaling it. This is done in the following code:
2. 创建瓶颈值(适当地缓存它们),以通过调整大小和缩放比例来标准化图像。 这是通过以下代码完成的:
```py
def run_bottleneck_on_image(sess, image_data,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册